iPhone App: Check In using Facebook Graph API - iphone

In my iPhone App I want to implement "Check in" feature (Facebook Places).
How can I check in using Facebook Graph API?

FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:#"me/checkins" withGetVars:nil];
NSLog(#"getMeButtonPressed: %#", fb_graph_response.htmlResponse);
//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSMutableArray *facebook_response =(NSMutableArray *)[fb_graph_response.htmlResponse JSONValue];//[parser objectWithString:fb_graph_response.htmlResponse error:nil];
[parser release];
NSMutableArray *feed =(NSMutableArray *) [facebook_response valueForKey:#"data"];
NSLog(#"%#",feed);
In the feed you can find the jason data of the places you have checked in..
If you get the "nil" data that means you have not checked in to any places so you have to first checkin to some places using your profile and FB.but if it is coming nil in that case only
and I am using the example from this referance :-https://github.com/reallylongaddress/iPhone-Facebook-Graph-API
so adjust it as per your requirement

Related

get twitter friends using my specific app

I am integrating twitter api on iphone device with specific application. I want to get list of followers using the same app.
Is it possible to get list of followers who are using the same app?
Thanks,
Jim.
Use this api call in your twitter api to get your followers in twitter
- (NSString *)getFollowersIncludingCurrentStatus:(BOOL)flag
{
NSString *path = [NSString stringWithFormat:#"statuses/followers.%#", API_FORMAT];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
if (!flag) {
[params setObject:#"true" forKey:#"lite"]; // slightly bizarre, but correct.
}
return [self _sendRequestWithMethod:nil path:path queryParameters:params body:nil
requestType:MGTwitterFollowerUpdatesRequest
responseType:MGTwitterUsers];
}

Facebook friend list

I am working on application where I want to access user friends list by login into facebook application. I am using xcode 4.2 ios 5 framework. I have gone through many tutorial but didn't find proper solution. please help me out.
- (void)getFriendsResponse {
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:#"me/friends" withGetVars:nil];// me/feed
//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary * facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
//init array
NSMutableArray * feed = (NSMutableArray *) [facebook_response objectForKey:#"data"];
NSMutableArray *recentFriends = [[NSMutableArray alloc] init];
//adding values to array
for (NSDictionary *d in feed) {
NSLog(#"see Dicitonary :%#",d );
facebook = [[Facebook alloc]initWithFacebookDictionary:d ];
[recentFriends addObject:facebook];
NSLog(#"Postsss :->>>%#",[facebook sender]);
[facebook release];
}
friends = recentFriends;
[self.tableView reloadData];
}
use facebook graph api. To get a list of their friend lists, you need read_friendlists extended permission. Graph Api reference and permissions

How to publish from iOS application to facebook wall without user amending message

I'm writing an iPhone game and want to publish the user's score to their facebook feed.
I've managed to knock together an example where the user agrees with the authorisation and then a dialog appears which they can confirm to publish on their wall, or not publish. This is almost ideal, except that the text is an editable field - so the user could amend their score and then publish. Ideally, I want the exact same mechanism, but without the ability to amend the message.
I'm assuming to do this, I would need to ask publish_stream permissions, followed by a Graph api call to post the message. I sourced this, but get an error 'An active access token must be used to query information about the current user.'.
I'll happily take a point in the right direction over the actual code change - any help much appreciated.
This is my first stackOverflow post, so be gentle please.
Thanks guys.
-Duncan
Original code (which publishes to wall but with amendable textbox)
//offer to facebook connect your score
facebook = [[Facebook alloc] initWithAppId:#"210645928948875"];
[facebook authorize:nil delegate:self];
NSMutableString *facebookMessage = [NSMutableString stringWithString:#"I scored a whopping "];
[facebookMessage appendString: [NSMutableString stringWithFormat:#"%d", currentScore]];
[facebookMessage appendString: [NSMutableString stringWithString:#". Can you beat me?"]];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"210645928948875", #"app_id",
#"http://duncan.co.uk/", #"link",
#"http://d.yimg.com/gg/goran_anicic/dunc.jpeg", #"picture",
#"dunc", #"name",
//#"Reference Documentation", #"caption",
#"Download the app NOW from the App Store", #"description",
facebookMessage, #"message",
nil];
[facebook dialog:#"stream.publish" andParams:params andDelegate:self];
Code to publish direct to wall (not proved) (which raises active token error):
/*Facebook Application ID*/
NSString *client_id = #"210645928948875";
//alloc and initalize our FbGraph instance
self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];
//begin the authentication process..... andExtendedPermissions:#"user_photos,user_videos,publish_stream,offline_access"
[fbGraph authenticateUserWithCallbackObject:self andSelector:#selector(fbGraphCallback:) andExtendedPermissions:#"user_photos,user_videos,publish_stream,offline_access"];
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:#"the message" forKey:#"message"];
[variables setObject:#"http://duncan.co.uk" forKey:#"link"];
[variables setObject:#"bold copy next to image" forKey:#"name"];
[variables setObject:#"plain text score." forKey:#"description"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"me/feed" withPostVars:variables];
NSLog(#"postMeFeedButtonPressed: %#", fb_graph_response.htmlResponse);
Solution found. The authentication should be called first. Once authenticated, this will call the fbGraphCallback function which will perform the post the the users stream.
All of this was made possible courtesy of http://www.capturetheconversation.com/technology/iphone-facebook-oauth2-graph-api. And bonus points goes to The Mad Gamer. Thanks a lot.
-(IBAction)buttonPublishOnFacebookPressed:(id)sender {
/*Facebook Application ID*/
NSString *client_id = #"123456789012345";
//alloc and initalize our FbGraph instance
self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];
//begin the authentication process.....
[fbGraph authenticateUserWithCallbackObject:self andSelector:#selector(fbGraphCallback:)
andExtendedPermissions:#"publish_stream" andSuperView:self.view];
}
-(void)fbGraphCallback:(id)sender {
if ((fbGraph.accessToken == nil) || ([fbGraph.accessToken length] == 0)) {
NSLog(#"You pressed the 'cancel' or 'Dont Allow' button, you are NOT logged into Facebook...I require you to be logged in & approve access before you can do anything useful....");
} else {
NSLog(#"------------>CONGRATULATIONS<------------, You're logged into Facebook... Your oAuth token is: %#", fbGraph.accessToken);
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:#"http://farm6.static.flickr.com/5015/5570946750_a486e741.jpg" forKey:#"link"];
[variables setObject:#"http://farm6.static.flickr.com/5015/5570946750_a486e741.jpg" forKey:#"picture"];
[variables setObject:#"You scored 99999" forKey:#"name"];
[variables setObject:#" " forKey:#"caption"];
[variables setObject:#"Download my app for the iPhone NOW." forKey:#"description"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"me/feed" withPostVars:variables];
NSLog(#"postMeFeedButtonPressed: %#", fb_graph_response.htmlResponse);
//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
[parser release];
NSLog(#"Now log into Facebook and look at your profile...");
}
[fbGraph release];
}
It looks like your permissions are a comma separated NSString, not an NSArray. The FB authorize: expects an NSArray, not an NSString.
Are you waiting for the response from the authenticate that calls fbGraphCallback ( is that code paraphrased?) I'm guessing your callback would show an auth failure because your perms are invalid. You have to wait for the auth to complete - otherwise you may not have the auth token before continuing.
FWIW - FB may have changed their rules in that app are not supposed to post to stream without letting a user modify the post text. A better route might be to go with your original code snip (waiting for auth if that's the issue?). You can put a link to your game in the post params and then put the score in the caption or description params (non-edit fields). You could then use the FB dialog and not let people change scores.
You can use Graph API.
[_facebook requestWithMethodName:#"stream.publish"
andParams:params
andHttpMethod:#"POST"
andDelegate:nil];

facebookErrDomain error 10000 when calling graph api Facebook ios

I'm struggling with the graph api for a few days now and I can't seem to get any further.
In my appdelegate i've placed the following code within the didFinishLaunching
facebook = [[Facebook alloc] initWithAppId:#"cut-app-id-out"];
NSArray* permissions = [[NSArray arrayWithObjects:
#"email", #"user_location", #"user_events", #"user_checkins", #"read_stream", nil] retain];
[facebook authorize:permissions delegate:self];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"test message from stackoverflow", #"message",
nil];
[facebook requestWithGraphPath:#"/me/feed" andParams:params andDelegate:self];
as you can see i'm trying to get the users feed out. I use the following code to place the data into a proper dictionary.
- (void)request:(FBRequest*)request didLoad:(id)result
{
if ([result isKindOfClass:[NSDictionary class]]) {
NSLog(#"count : %d ", [result count]);
NSArray* resultArray = [result allObjects];
NSLog(#"count : %d ", [result count]);
result = [resultArray objectAtIndex:0];
NSLog(#"count : %d ", [result count]);
result = [result objectAtIndex:0];
}
}
But the didFailWithError: function gives me the following error:
The operation couldn’t be completed. (facebookErrDomain error 10000.)
I've place the FBRequestDelegate in my interface file as following:
#interface TabbedCalculationAppDelegate : NSObject
<FBRequestDelegate>{
Is there something what i'm missing?
There's a lot more needed to handle Facebook responses, especially after authorization. You're not going to be able to make calls against the Facebook API immediately after the authorize method. Please see their sample code which shows how to respond to the various events which you will need to do, most importantly the fbDidLogin and fbDidNotLogin ones. Only once you have a successful login should you access the Graph API.
In addition, it looks like you're trying to post a message with the Graph API. Unfortunately that's not the way to do it and a call like [facebook requestWithGraphPath:#"me/feed" andDelegate:self]; is meant for read-only use. Again, look at the above link for an example of how to use the publish_stream permission (their code has a publishStream example method).

Publish to Facebook wall from iPhone application

No Matter what i do, i cannot get a post published to an application page wall (the app being logged into) via an iPhone application. I'm able to log in using FBLoginDialog and then retrieve data to populate a tableview, however when i click a button to publish some test content it doesn't work. Here is the button action:
- (void)compose:(id)sender;
{
NSString *tid=#"115372005166292";
NSString *body = #"My Test";
NSArray *obj = [NSArray arrayWithObjects:body,[NSString stringWithFormat:#"%#", tid],nil];
NSArray *keys = [NSArray arrayWithObjects:#"message",#"target_id",nil];
NSDictionary *params = [NSDictionary dictionaryWithObjects:obj forKeys:keys];
[[FBRequest requestWithDelegate:self] call:#"facebook.stream.publish" params:params];
}
I have also used the FBStreamDialog which works, however i'm faced with two issues there. The dialog lacks customization and i'm unable to handle the callback when the item is posted (e.g. reload the tableview)
I've been searching the internet and all of the examples are similar to the code above, so i'm not sure what i could be missing.
Thanks
You need to ask for extended permissions. After login show this:
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = #"status_update";
[dialog show];
Doc: http://github.com/facebook/facebook-iphone-sdk/#readme