Using 'Like' with the Facebook Graph API on iOS - iphone

I am using the latest Facebook SDK for iOS and Graph API. Works Great.
I'm trying to 'Like' status updates, doing the following:
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *messageID = (NSString*)[managedObject valueForKey:#"message_id"];
NSLog(#"Like: %#", [NSString stringWithFormat:#"%#/likes", messageID]);
[facebook requestWithGraphPath:[NSString stringWithFormat:#"%#/likes", messageID] andParams:nil andHttpMethod:#"POST" andDelegate:self];
However this returns an error from Facebook:
facebookErrDomain error 10000.
Anyone know why this is?

Figured it out. You cannot pass nil to the parameters. So I created an empty NSMutableDictionary, and passed that. Worked fine. (By the way: it’s not possible to like a page this way.)

Related

Graph API iOS picture

I have a graph api call from my ios application. It looks something like this:
[[appDelegate facebook] requestWithGraphPath:[NSString stringWithFormat:#"%i/picture", [[userData objectForKey:#"id"] intValue] andDelegate:self];
(might be some typos)
But in the request did load when i nslog the result, it is (null). Graph API says that you need to use fields=picture or something to get the url. How would I do this? If it is possible could somebody show me some example code?
You don't need an actual Graph API call to load a user's facebook picture. Simply construct a url like this, and it will return the specified user's facebook image:
NSURL *fbPictureURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://graph.facebook.com/%#/picture", [userData objectForKey:#"id"]];
You can then do with that what you want, like load it in an UIImageView.
See my answer on this post to see how to get the picture URL using requestWithGraphPath:
iOS Facebook Graph API Profile picture link

Create event on Facebook

I am trying to create an event using graph API with following code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"venue name",#"name",
#"2012-01-13T17:00:00+0000",#"start_time",
#"2012-01-16T01:30:00+0000",#"end_time",#"location",#"location name ch",#"1234567890",#"id", nil];
[self.facebook requestWithGraphPath:#"me/events"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
but when I am trying to create the event, an alert comes with "Facebook Fail bad URL". Can any one suggest what I am doing wrong or what I am missing in parameters or anywhere or is there any other method?
-Thanx in advance
Maybe because there is no param id.
If you want to set venue location, use location_id.
Try doing the same thing with the same parameters here: https://developers.facebook.com/tools/explorer and see what the error message is.

i want to share friend's post via graph api

I want to share some posts in facebook via graph api.
But there's no api like this. only "feed" exists.
I tried to use "me/feed" graph api action to share my friend's post(and post in page). but it's not same as i shared in facebook website. i want to know how.
source is..
NSMutableDictionary *fbArguments = [[NSMutableDictionary alloc] init];
NSString *linkURL = #"http://media.daum.net/society/others/view.html?cateid=1067&newsid=20120106140112792&p=munhwa&RIGHT_COMM=R4";
[fbArguments setObject:linkURL forKey:#"link"];
[facebook requestWithGraphPath:#"me/feed"
andParams:fbArguments
andHttpMethod:#"POST"
andDelegate:self];
[fbArguments release];
And I noticed there's no action for sharing friend's post(or photo), page's post via facebook iphone app. (so weird. don't you need this action?)
what can i do? can you help me?
Thanks.
i'v succeeded sharing photo. that is 'Link'.
source is
NSMutableDictionary *fbArguments = [[NSMutableDictionary alloc] init];
NSString *linkURL = #"https://www.facebook.com/photo.php?fbid=324225380935287&set=a.265279620163197.68309.194442110580282&type=1";
[fbArguments setObject:linkURL forKey:#"link"];
[fbArguments setObject:#"good!" forKey:#"message"];
[facebook requestWithGraphPath:#"me/feed"
andParams:fbArguments
andHttpMethod:#"POST"
andDelegate:self];
[fbArguments release];
i added message. and this is perfectly same as i shared via facebook web.
but there is one problem. this never makes back reference(trackback?).
if I share a photo via facebook web, I can see "5 shares" upper comment list, and my username is is there.
But this way, There is no my username. No trackback.
what can i do?
thanks.

iPhone Facebook image upload not working, tried everything

I'm losing my mind over trying to get Facebook SDK for iPhone to upload UIImage.
Here's what I'm doing:
1) Creating facebook property:
facebook = [[Facebook alloc] initWithAppId:#"111111111"];
2) Calling authorize:
[facebook authorize:[NSArray arrayWithObjects:#"publish_stream", nil] delegate:self];
3) Setting params:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image, #"picture", nil];
4) Calling post:
[facebook requestWithMethodName:#"photos.upload" andParams:params andHttpMethod:#"POST" andDelegate:self];
When loging in I get the authorize dialog. When trying to upload I receive error 101, Invalid API Key. I've copied the key from FB, I've included it as shown above and I've also included it in .plist (fbAPI_KEY). What the hell am I still missing here? When asked to authorize it did show the name of the app just fine so the key must be correct. I can also post feeds and they appear on users wall, but images just won't upload.
That's a bit weird, I've got the exact same four lines of code which work fine for me. (Although, your app id is a bit shorter than it should be, mine is roughly twice that size).
One thing you may be forgetting about: when are you using each line? You should wait till each of the previous tasks is completed by using the facebook delegates, eg:
- (void)fbDidLogin; //part of the <FBSessionDelegate> protocol
Use these methods to control when the next part of the uploading process should occur, and check for errors along the way. You may be trying to send the photo before the login process has actually finished - use the delegate methods to prevent this.
I think you have to use graph API for uploading images
Check Out:
Ref URL: http://www.raywenderlich.com/1626/how-to-post-to-a-users-wall-upload-photos-and-add-a-like-button-from-your-iphone-app
Hope this helps....

Facebook oauth/access_token missing

Dunno if Im missing something but here goes. Im trying to get an access_token for my application so that it can go and look up events for certain public groups on facebook, without requiring a user to be logged in.
Im trying to get an access_token from
https://graph.facebook.com/oauth/access_token?client_secret=foobar&client_id=foobar&grant_type=client_credentials&format=json&sdk=ios
This returns a string: access_token=xxxx|ugtqdoWfvvo5_S-Fo2D7_I4rdbc
Thats nice and all, but its no json. Any insights on why the returned string is not json encoded ?
Note:
Im using the Facebook ios SDK function like so
[_facebook requestWithGraphPath:#"oauth/access_token" andParams:params andHttpMethod:#"POST" andDelegate:self];
This is a BUG: https://developers.facebook.com/bugs/325262010847554
Facebook's OAuth 2.0 implementation is clearly in violation of the spec: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-25#section-5.1
I'm using Server-side Web App flow and have the same issue that you describe for the iOS SDK.
This is fixed as of v2.3 of the graph api. Specify the version by using endpoint https://graph.facebook.com/v2.4/oauth/access_token.
It's easy to accidentally land on the wrong version of the facebook API docs.
Here's a snippet to extract your access token and replace the pipe character with the proper escape...
NSURL *accessTokenURL = [NSURL URLWithString:#"https://graph.facebook.com/oauth/access_token?client_id=XXXXXXXXXXXXX&client_secret=XXXXXXXXXXXXXXXXXXX&grant_type=client_credentials"];
NSString *accessTokenResponse = [NSString stringWithContentsOfURL:accessTokenURL encoding:NSUTF8StringEncoding error:NULL];
if(accessTokenResponse != nil) {
NSMutableString *accessToken = [NSMutableString stringWithString:[accessTokenResponse substringFromIndex:13]];
[accessToken replaceOccurrencesOfString:#"|" withString:#"%7C" options:NSLiteralSearch range:NSMakeRange(0, [accessToken length])];
}
Follow up.
The way I understand the FB ios SDK is that your delegate function will receive an object such as NSArray or NSDictionnary to work with. Looking into the internals of the FB SDK classes it seems that all response are parsed using the SBJSON parser. If the response is not json than that will fail.
[_facebook requestWithGraphPath:#"261247595170" andDelegate:self];
returns nice json. No problems there.
[_facebook requestWithGraphPath:#"oauth/access_token" andParams:params andHttpMethod:#"POST" andDelegate:self];
String returned. SBJSON parser fails.
This seems to be an inconsistency in the FB graph service.
One could write a special function to handle this problem, but if FB decides to change the format of the string, then all IPhone App would stop working, and need to update. Not cool.
If you're using Facebook SDK, I believe that they return NSArray and NSDictionnary
I might be wrong, but try with an objectForKey:#"access_token"
Any insights on why the returned
string is not json encoded ?
Yeah, the access token isn't supposed to be JSON-encoded. And there's arguably little value in JSON-encoding a single string anyway.
Why are you expecting it to be so?
Seems I was misinformed about this. The spec states that application/json is to be used for the response body.