How to post a pic to Tumblr using TMTumblrSDK in iOS - 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.

Related

MSGraphSDK user details API callback not responding back when user password changed in iOS

I tried to get the user details using MSGraph SDK in iOS using below API method. Iam successfully received the user details all the time. But when user charged their password or update their credentials, i received the oauthConnection Error: only in log. And i didn't receive any call back in the below API. Why it is not responding back when any kind of error occurred? Please help me. Thanks in advance.
[MSGraphClient setAuthenticationProvider:self.authProvider.authProvider];
self.graphClient = [MSGraphClient client];
[[[self.graphClient me]request]getWithCompletion:^(MSGraphUser *response, NSError *error) {
if(!error){
// Im able to get back here
}
else{
//Im not received any call back here when user changed their password or any error occurred.
[self.authProvider disconnect];
}
}];`
I am kinda new to MS Graph, so I might be missing something, but your graphClient declaration seems a little bit poor to me.
Try to download this sample: https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2
And check it's declaration of graphClient.
You might be missing the part which refreshes the token?

Pinterest SDK authenticate permission fail

I am trying to pin an image to pinterest. However, when I tried to authenticate the user, it fails.
I am calling the following code on button click, which takes me to pinterest app and the authentication dialog is shown,
[[PDKClient sharedInstance] authenticateWithPermissions:#[PDKClientReadPublicPermissions,
PDKClientWritePublicPermissions,
PDKClientReadPrivatePermissions,
PDKClientWritePrivatePermissions,
PDKClientReadRelationshipsPermissions,
PDKClientWriteRelationshipsPermissions]
withSuccess:^(PDKResponseObject *responseObject)
{
PDKUser *user = [responseObject user];
NSLog(#"%# authenticated!", user.firstName);
} andFailure:^(NSError *error) {
NSLog(#"authentication failed: %#", error);
}];
Also nothing prints in the console. I am unable to access the responseObject inside the block.
when I click okay, the authentication fails.
I have no idea where I could be wrong. I followed the steps mentioned in the pinteret/Developers . Can anyone guide me in the right way?
Probably there is an error in the callback URL you are passing and /or which is provided by you in the app settings. Check that Url, as a recommendation.

Fetch Facebook Posts for Public Page using Facebook SDK

I'm trying to fetch Facebook posts for a public page using the Facebook SDK for iOS. I can't seem to figure out how to get and then use the access token I need to make this request. Let's say it's the New York Times page. This shouldn't require any permissions, so I should be able to use the App Access Token...but again, I can't figure out how to get & use that.
The code I am using looks like this:
[FBRequestConnection startWithGraphPath:#"/nytimes/posts" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"DATA: %#", [result data]);
NSLog(#"ERROR: %#", error);
}];
I keep receiving an error saying that an access token is required.
Please help!
It means it asking you a permission to access the public post in view did load method put one line code like (readPermissions = #[#"public_profile", #"email",#"user_friends",#"user_likes",#"user_groups"];)
, for more details see this https://developers.facebook.com/docs/facebook-login/permissions/v2.2.

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.

Facebook Like/Unlike gives error message

I am building an application which implements Facebook. Through this application I can like and comment on a post. I am fetching Home feeds for the logged in user. Now for Like operation I am using the graph API :
https://graph.facebook.com/POST_ID/likes?&access_token=ACCESS_TOKEN
with HTTPMethod: POST
Here, the POST_ID is the ID I am getting for each feed and the access token of the logged in user.
Now in most of the cases I can like the feed using this API. But some posts don't have Like Connections. How do I know which feed has a like connection & which does not.
Now coming to Unlike. For Unlike operation I am using the graph API :
https://graph.facebook.com/POST_ID/likes?&access_token=ACCESS_TOKEN
with HTTPMethod: DELETE
I can unlike some posts or feeds using this API. But for some I get an error message. In that case i am using for example:
This is the
POST_ID = 12345_67890. When I get error message for this I am using the 67890 as the POST_ID in this case & I am getting success to unlike a post/feed.
Again in using this 67890 as POST_ID gives error in some cases & in that case I am using OBJECT_ID if exists in the feed I am receiving. And I am getting true response in some cases.
But in rest of the cases I can't find any solution for Like & Unlike of a feed/post in Facebook.
Waiting for positive reply.
if you are using correct post_id of feed than it will never produce any error while liking/disliking post on facebook by following code
if do you want to like than change HTTPMethod to POST otherwise set DELETE for dislike. there is no need of accesstoken to call this api.if you are using so it will not produce any error
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/likes",#"Post_id"] parameters:nil HTTPMethod:#"DELETE" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
{
NSLog(#"error: %#", error.localizedDescription);
}
else
{
NSLog(#"ok!! %#",result);
}
}];

Resources