Post tweets through Objective-c Using STTwitter - ios

So here is my problem. I am trying to authenticate an app and post a tweet on the twitter using STTwitter API for iOS. Here is my code using STTwitter framework.
STTwitterAPI *twitter= [STTwitterAPI twitterAPIWithOAuthConsumerName:#"mytwitterdisplayname"
consumerKey:#"consumerkey"
consumerSecret:#"consumersecret"
username:#"myloginuseremailid"
password:#"password"];
And using this object twitter as follows
[twitter postStatusUpdate:#"test" inReplyToStatusID:nil
latitude:nil
longitude:nil
placeID:nil
displayCoordinates:nil
trimUser:nil
successBlock:^(NSDictionary *status) {
// ...
} errorBlock:^(NSError *error) {
// ...
}];
However, each time I run this code I get following error as authentication failure.
"Error Domain=STHTTPRequest Code=220 "Your credentials do not allow access to this resource." UserInfo=0xdf46550 {NSLocalizedDescription=Your credentials do not allow access to this resource.}"
Is there something wrong I am doing? Any help is much appreciated.
I am using iOs7 and Xcode 5.0.2

Related

Failed to fetch full profile details from LinkedIn API

I tried to fetch full profile details from LinkedIn API. I referred a sample app also. In my app I tried,
[LISDKSessionManager createSessionWithAuth:[NSArray arrayWithObjects:LISDK_FULL_PROFILE_PERMISSION, LISDK_EMAILADDRESS_PERMISSION, nil] state:nil showGoToAppStoreDialog:YES successBlock:^(NSString *returnState) {
[self.delegate didSuccessfullyLogIntoLinkedIn];
} errorBlock:^(NSError *error) {
[self.delegate fetchingFailedWithError:error];
}];
This code gives me an error
The operation couldn’t be completed. (LISDKAuthError error 5.)
But in the sample app which is provided by the LinkedIn, This same code is working. I went through my app authentications. It has only following fields. I think the problem is, In this list there is no r_fullprofile field.
Is this the problem? Is it possible to add r_fullprofile field to this list?
Although basic access gives you only 4 fields, an answer is "Yes, it is possible". If you subscribe to LinkedIN Partnership Programs.

Retweet using STTwitter API

I have tried to add the retweet concept in my application using STTwitter API with following method after user authentication:
[twitter postStatusRetweetWithID:[NSString stringWithFormat:#"691544087921606656"] successBlock:^(NSDictionary *status) {
NSLog(#"status..%#",status);
} errorBlock:^(NSError *error) {
NSLog(#"error..%#",error);
}];
But it is showing following error:
Error Domain=STTwitterTwitterErrorDomain Code=220 "Your
credentials do not allow access to this resource."
UserInfo={NSUnderlyingError=0x7b170ca0 {Error Domain=STHTTPRequest
Code=403 "HTTP Status 403: Forbidden"
UserInfo={NSLocalizedDescription=HTTP Status 403: Forbidden}},
NSLocalizedDescription=Your credentials do not allow access to this
resource.}
If anyone has experienced with the STTwitter API. Suggest me some idea to get rid from this error.
Thanks in advance.

How to post a pic to Tumblr using TMTumblrSDK in iOS

I am trying to integrate Tumblr into my app for simply posting of pics into tumblr.
I am confused in following the authentication process of tumblr.
I registered the app.
I have the consumer key, and the consumer secret key.
I have requested for the token and the token secret key by using OAuthConsumer.
However I am failing to do the next step which is posting a photo .
This is the code I'm using to authenticate:
[[TMAPIClient sharedInstance]authenticate:#"myappURLScheme" callback:^(NSError *err) {
NSLog(#"authentication failed %#",err);
}];
And this takes me to the safari tumblr page, to do the Allow/ Not allow process.After I click on Allow, it takes me to the tumblr app. But the pic is not posted.
Here is what I tried to post the pic:
[[TMAPIClient sharedInstance] photo:#"Sample Upload"
filePathArray:#[[_imagesPath stringByAppendingPathComponent:
#"tm.png" ]]
contentTypeArray:#[#"image/png"]
fileNameArray:#[#"tm.png"]
parameters:#{#"caption" : #"Caption"}
callback:^(id response, NSError *error) {
if (error)
NSLog(#"Error posting to Tumblr %#",error);
else
NSLog(#"Posted to Tumblr %#",error);
}];
HEre I get the error:
Error posting to Tumblr Error Domain=Request failed Code=404 "(null)"
The response parameter is also null.
I believe the authentication is a success,I am also able to get the user info from the Tumblr. but I'm not sure why the pic is not posted .
Is Sample Upload your blog? I have to admit Tumblr's naming conventions are really bad, but if you check the code, you can see you need to pass the blog name there.
- (void)photo:(NSString *)blogName filePathArray:(NSArray *)filePathArrayOrNil contentTypeArray:(NSArray *)contentTypeArrayOrNil
fileNameArray:(NSArray *)fileNameArrayOrNil parameters:(NSDictionary *)parameters callback:(TMAPICallback)callback;
Otherwise make sure you set the OAuthConsumerKey, OAuthConsumerSecret, OAuthToken and OAuthTokenSecret before sending the request.
Your code looks fine otherwise, about the same worked for me.

Facebook Login Invalid Scope

I'm using Facebook login, and all of a sudden it stopped working saying "Invalid Scope: user_Friends".
I thought this error was because of the upgrade of the Graph API from v1.0 to v2.0 but my SDK is on the version 3.18 which already comes with GraphAPI v2.0
does any one knows what am I doing wrong? Do I need to make any modifications to be compatible with GraphAPI v2.0?
this is my code I ask for permissions
- (void)viewDidLoad
{
[super viewDidLoad];
originalFrame = menuBG.frame;
NSLog( #"### running FB sdk version: %#", [FBSettings sdkVersion] );
if (FBSession.activeSession.isOpen)
{
NSLog(#"Is Connected");
flagFaceCon = YES;
}
else
{
flagFaceCon = NO;
NSLog(#"Is NOT Connected");
}
loginView.readPermissions = #[#"public_profile", #"email", #"user_Friends"];
}
You may also get this error if your app is public but it hasn't been app reviewed yet. Though the docs don't make this entirely obvious. It's a bit fine-print and the error message doesn't clue you into that.
try
user_friends
not
user_Friends
I used for scope user_Friends, but the correct is user_friends (Lower case).

Twitter oauth/access_token 401 Error

I've been working on an all that uses the full OAuth app flow, and I have been running into an issue where I only get back a 401 = "Invalid or expired token" error. I've checked my request with the documentation, and everything looks correct, and I'm stumped. Below is the details of my request.
URL
https://api.twitter.com/1.1/oauth/access_token
HTTP Method
POST
Headers
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth oauth_consumer_key="CONSUMER_API_KEY", oauth_nonce="B4D43B0C-A348-4EB6-9C0B-8B0F4FE8", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1397724299", oauth_version="1.0", oauth_token="TOKEN_FROM_REQUEST_TOKEN_API", oauth_signature="ulYIzTacwC%2FeGUdoCPYsrFEqg4A%3D"
HTTP Body
oauth_verifier=OAUTH_VERIFIER_FROM_REQUEST_TOKEN_API
I have no issues getting the oauth/request_token API to work, and I have appropriately set the permissions in Twitter's app settings. Does anyone have any idea what's going on with this?
Thanks for any help you all may be able to offer.
-- UPDATE --
Another thing to note is that I'm using the STTwitter library to make the requests. It did not have a built-in method to handle the oauth/authorize or oath/authenticate API methods so I'm using the code below.
// get request token, and present login screen
STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:twitterApiKey consumerSecret:twitterApiSecret];
[twitter postTokenRequest:^(NSURL *url, NSString *oauthToken)
{
authWebViewController = [[TWAuthWebViewController alloc] init];
authWebViewController.url = [NSURL URLWithString:[NSString stringWithFormat:#"https://api.twitter.com/oauth/authorize?oauth_token=%#", oauthToken]];
authWebViewController.completion = ^(TWAuthWebViewController *authViewController, NSURL *oauthCallbackURL)
{
// get the request token and verifier from the URL
NSString *oauthToken = [TWLoginBusiness getOAuthTokenFromURL:oauthCallbackURL];
NSString *oauthVerifier = [TWLoginBusiness getOAuthVerifierFromURL:oauthCallbackURL];
// get user data with the oauth token
[twitter postResource:#"oauth/access_token"
baseURLString:#"https://api.twitter.com/1.1"
parameters:#{#"oauth_verifier" : oauthVerifier}
uploadProgressBlock:nil
downloadProgressBlock:nil
successBlock:^(NSDictionary *rateLimits, id response)
{
NSLog(#"Reponse: %#", response);
completion(nil, nil);
} errorBlock:^(NSError *error)
{
NSLog(#"Error: %#", error);
completion(nil, error);
}];
};
presentAuthController(authWebViewController);
} oauthCallback:twitterApiCallback errorBlock:^(NSError *error)
{
completion(nil, error);
}];
One last note. The part that actually displays the web view controller is not listed here. I wanted to keep the code snippet here focused on the actual API methods, and not the UI logic. Just be assured that the line right after authWebViewController.url.... displays the web view, and then the completion block is called after the user completes the authentication on the Twitter web page. Also the two methods getOauthTokenFromURL and getOauthVerifierFromUrl do in fact return the correct token and verifier. The STTwitter library actually saves out the token it's self, so that is why it's not manually passed into the logic below. The logic generates the request above.
Thanks
The full OAuth flow is already implemented in STTwitter library.
Check out iOS demo for a working example of web-based authentication through Safari.
What you are trying to do here is a web-based authentication inside the application.
Although it is totally feasible, I did not include this workflow in the demo project because it is considered a bad practice.
Indeed, the point of OAuth is that the user does not want to enter her Twitter credentials in your own application, but asks Twitter to send your app dedicated OAuth tokens instead.
Let me know if you need more help with STTwitter.

Resources