IOS: facebook sdk per my own post - ios

I have a question about sdk facebook integration with my iOS app.
In my app I want authenticate the users with the facebook login and it's all clear here
http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/
In this app the users should post something in their facebook account, as a photo or a message, not complicated yet.
The problem is... is it possible detect the number of comments and like that users receive for their posts? Is there something in facebook sdk that allow to obtain this information?
thanks

Use following code and you can get more idea from Facebook iOS SDK 3.0, implement like action on a url? also.
NSString *urlToLikeFor = facebookLike.titleLabel.text;
NSString *theWholeUrl = [NSString stringWithFormat:#"https://graph.facebook.com/me/og.likes?object=%#&access_token=%#", urlToLikeFor, FBSession.activeSession.accessToken];
NSLog(#"TheWholeUrl: %#", theWholeUrl);
NSURL *facebookUrl = [NSURL URLWithString:theWholeUrl];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:facebookUrl];
[req setHTTPMethod:#"POST"];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[responseData bytes]];
NSLog(#"responseData: %#", content);

Related

Send MMS using Twilio in ios

I want to send MMS using Twilio.
I am request one twilio url which is work fine on SMS but not MMS and I want to know what should change so i am sending MMS using Twilio in iOS.
Here is my code.
NSLog(#"Sending request.");
// Common constants
NSString *kTwilioSID =#"Twilio SID";
NSString *kTwilioSecret =#"Twilio Secret";
NSString *kFromNumber = #"From Phone Number";
NSString *kToNumber = #"To Phone number";
NSString *kMessage=#"Hello This is Pintu vasani";
// Build request
NSString *urlString = [NSString stringWithFormat:#"https://%#:%##api.twilio.com/2010-04-01/Accounts/%#/SMS/Messages", kTwilioSID, kTwilioSecret, kTwilioSID];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:#"POST"];
// Set up the body MediaUrl
NSString *bodyString = [NSString stringWithFormat:#"From=%#&To=%#&Body=%#", kFromNumber, kToNumber, kMessage];
NSData *data = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
NSError *error;
NSURLResponse *response;
NSData *receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// Handle the received data
if (error) {
NSLog(#"Error: %#", error);
} else {
NSString *receivedString = [[NSString alloc]initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(#"Request sent. %#", receivedString);
}
Twilio developer evangelist here.
You seem to be using the old, deprecated Sms resource which doesn't support MMS. You really want to be using the Messages resource which does work.
On a separate note, I would not recommend making API calls directly to Twilio from your iOS application (or any other client application). To do this you would need to embed your Twilio credentials within the application which is dangerous. I would recommend sending the SMS/MMS from a server side application as in this example.

Twitter iOS GET statuses/home_timeline using Parse

This will be my first iPhone app and I am running into difficulties that I thought I'd be able to find a tutorial on, but alas.... nothing on the inter webs that I can find.
I'm trying to get an initial 20 or so tweets from a signed in user (signed in using Parse's Twitter authentication) and I can't seem to get it to work. I put a breakpoint in when I get an error and this is what it shows:
I'm contemplating abandoning Parse all together and doing my own authentication using https://github.com/nst/STTwitter but wanted to quickly see if there was a way to simply do what I am trying to. The code is question is at this github: https://github.com/johndangerstorey/twiz and outlined below as found in my MyLoginViewController.m file:
NSString *bodyString = [NSString stringWithFormat:#"https://api.twitter.com/1.1/statuses/home_timeline.json?screen_name=johnDANGRstorey"];
// Explicitly percent-escape the '!' character.
bodyString = [bodyString stringByReplacingOccurrencesOfString:#"!" withString:#"%21"];
NSURL *url = [NSURL URLWithString:bodyString];
NSMutableURLRequest *tweetRequest = [NSMutableURLRequest requestWithURL:url];
tweetRequest.HTTPMethod = #"GET";
tweetRequest.HTTPBody = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
[[PFTwitterUtils twitter] signRequest:tweetRequest];
NSURLResponse *response = nil;
NSError *error = nil;
// Post status synchronously.
NSData *data = [NSURLConnection sendSynchronousRequest:tweetRequest
returningResponse:&response
error:&error];
// Handle response.
if (!error) {
NSLog(#"Response: %#", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
} else {
NSLog(#"Error: %#", error);
}
Thanks for your reply and help.
I figured it out, GET requests don't require .body or .method requests so I just removed
tweetRequest.HTTPMethod = #"GET";
tweetRequest.HTTPBody = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
and was golden.

message:(#200) App does not have permission to make this call in ios application using facebook sdk

I want to like and comment in my iOS application.But the problem is whenever I call my API the response comes in the form of this `error:message:(#200)'. App does not have permission to make this call and sometimes it will give input parameter is required.The permissions i give are 'basic_info','email','user_likes' and 'read_stream'. I am passing object id and access token in my like and comment API.
Like API code:
NSString *theWholeUrl = [NSString stringWithFormat:#"https://graph.facebook.com/%#/likes?access_token=%#",self.friendId,[FBSession activeSession].accessTokenData.accessToken];
NSLog(#"Value of theWholeUrl%#",theWholeUrl);
NSURL *facebookUrl = [NSURL URLWithString:theWholeUrl];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:facebookUrl];
[req setHTTPMethod:#"POST"];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[responseData bytes]];
You need the publish_actions permission to be able to like and comment on content programmatically via the API.

How do I create a post for Disqus from iOS?

I'm developing an application for a client. This app enables user to read and post comment. Our client website have already used Discus. Now that we can retrieve the comment and display it natively. But we find no way to create a post and send it to Disqus. Does anyone have some experiences with Disqus on iOS ?
Any idea will be much appreciated.
Edit : our client website has an authentication system already and thus we also integrate that system to our app. Every time user post a comment in the app, we'll use his/her authentication information. We don't want user to authenticate again.
Here is a great solution which helps easily integrate Disqus into iOS apps https://github.com/moqod/disqus-ios. Works like a charm out of the box.
Not only you can make posts, but also authorize thru social networks and respond to comments.
You have the API set up on your server, correct? Then post a request to your server, pass it whatever API keys and credentials you need, and have the server make a post to the Disqus API on behalf of the client. Basically, build your own iOS API for interfacing with the Disqus API through your server.
Even better though would be to directly interact with the Disqus server by making requests using NSURLRequest/Connection. For more information on Disqus requests look here. That would make your app faster and be less error prone, unless you are doing some critical activity on your server, other than just posting and displaying comments.
#RahuGupta: Sorry if it's too late for a response. I posted comment using SSO, I don't know about posting as guest. But it should be easier.
In my case I post a comment using third party authentication server which means we authenticate users by ourselves. The technique called SSO. You may want to read the documentation about SSO on Disqus.
In case you need code snippet in objective-c :
NSMutableDictionary *dico = [[NSMutableDictionary alloc] init];
[dico setValue:[NSString stringWithFormat:#"uniqueId_%#",comment.authorID] forKey:#"id"];
[dico setValue:comment.authorName forKey:#"username"];
[dico setValue:comment.authorEmail forKey:#"email"];
NSString *message = [dico JSONRepresentation];
NSString *message64Based = [DataPost base64String:message];
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
NSString *secret = DISQUS_API_SECRET;
NSString *api_key = DISQUS_API_PUBLIC;
//comment.threadID will makes the app crashed, because when comment is not fully loaded, it's nil
NSString *threadID = [NSString stringWithFormat:#"%#",comment.threadID];
NSString *commentMessage = [[comment.rawMessage stringByReplacingOccurrencesOfString:#"=" withString:#"%3D"] stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSString *host = #"http://example.com";
NSString *referrer = #"example.com";
NSString *hmac = [self hashedValue:secret andData:[NSString stringWithFormat:#"%# %.0lf",message64Based, timeStamp]];
NSString *remote_auth_s3 = [[[NSString stringWithFormat:#"%# %# %.0lf", message64Based, hmac, timeStamp] stringByReplacingOccurrencesOfString:#"=" withString:#"%3D"] stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSMutableURLRequest *uploadRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"http://disqus.com/api/3.0/posts/create.json"] cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 60.0f];
NSMutableData *postData = (NSMutableData *)[[NSString stringWithFormat:#"_format=json&thread=%#&message=%#&remote_auth=%#&api_key=%#&strict=1", threadID , commentMessage, remote_auth_s3 , api_key] dataUsingEncoding:NSUTF8StringEncoding];
[uploadRequest setHTTPMethod:#"POST"];
[uploadRequest setHTTPBody: postData];
[uploadRequest setValue:[NSString stringWithFormat:#"%d", [postData length]] forHTTPHeaderField:#"Content-Length"];
[uploadRequest setValue:referrer forHTTPHeaderField:#"referrer"];
[uploadRequest setValue:host forHTTPHeaderField:#"host"];
[uploadRequest setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
NSHTTPURLResponse *response=nil;
NSError *error = nil;
[NSURLConnection sendSynchronousRequest:uploadRequest returningResponse:&response error:&error];

Need alternative to Facebook Open Graph og.likes action for Facebook page

While attempting to publish a like connection between a Facebook user and a Facebook page (using Facebook's Open Graph og.likes action type) within an iOS app I received the following error:
{"error":{"message":"(#100) Like actions are not yet supported against objects of this type.","type":"OAuthException","code":100}}
After doing a little research I found that open graph like actions can not be published against Facebook pages. My understanding is that my only other option would be to embed the standard like button with a UIWebView.
My question:
Is there anything else I can do to create a similar or meaningful open graph connection between a Facebook user and a Facebook page without using a UIWebView?
Below is some of my code, I successfully used it to publish a like against a non-Facebook page to verify the issue wasn't something else:
if(isFacebookServiceAuthorized)
{
NSLog(#"Facebook service is authorized");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *accessToken = [defaults valueForKey:#"kSHKFacebookAccessToken"];
id userInfo = [defaults valueForKey:#"kSHKFacebookUserInfo"];
NSString *userID = [userInfo objectForKey:#"id"];
NSLog(#"Access Token: %# and userid: %#", accessToken, userID);
NSString *devID = FACEBOOK_DEV_USERID
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/og.likes", devID]];
NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:url];
[request1 setURL:url];
[request1 setHTTPMethod:#"POST"];
NSString *body=[NSString stringWithFormat:#"access_token=%#&object=OBJECT_TO_LIKE", accessToken];
[request1 setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
NSError *error;
NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:request1 returningResponse:&response error:&error];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(#"string..:%#",string);
}

Resources