How can I get facebook photo like count in iPhone SDK? - ios5

How can I get the count of facebook photo likes and dislikes in an iPhone application using graph api?
Thanks in advance.

Just call a new request with the FB object:
[facebook requestWithGraphPath:#"PHOTO_ID/likes"];
Replace PHOTO_ID with the Facebook ID of the photo you're interested in. This call will return an array with all like information for that photo.
In the -facebook requestDidLoad: method, just get the count of that array to return the number of likes.
NSInteger likeCount = [result count];

Related

iOS facebook sdk how to download album, profile photos data

I would like to allow my iPhone App users to view and select from their facebook profile photos, download the photo to use as a profile pic. I am currently using the Facebook SSO SDK and successfully logging in and accessing Graph information. Have tried to access photo information (after successful SSO login) using
[facebook requestWithGraphPath:#"me/albums"];
but I just get an empty data object in return. I've tried using the Facebook API explorer, which is very helpful, and it does give me data for /picture and /photos and /albums. For some reason I don't get the same data using requestWithGraphPath with me/albums, me/picture or me/photos. Just plain "me" works fine but doesn't give me any picture info. Can anybody tell me what I'm doing wrong?
Note: this is the API reference: Facebook Graph API
I did get picture profile to work like this:
[facebook requestWithGraphPath:#"me?fields=picture"];
Update: really I want all of the Profile Photos which is a photo album so I need to know how to access albums through iOS. The profile picture I have successfully obtained now.
I have added permissions "user_photos" and "friends_photos" for photo albums according to API:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"user_likes",
#"user_birthday",
#"email",
#"publish_stream",
#"publish_actions",
#"user_photos",
#"friends_photos",
nil];
[facebook authorize:permissions];
When I say I'm getting empty data, this is the JSON result (in request:didLoad:) that gets returned:
{
data = (
);
}
From my log file output:
- (void) request:(FBRequest *)request didLoad:(id)result{
NSLog(#"%#",result);
}
Final Note: What finally worked was to use another device, which updated my permissions and then everything started working! My best guess is that the emulator and my iPhone were not updating my facebook permissions so I was being denied access to photos and getting an empty data array.
This SO question was a big help also: How to get photos of a facebook album in iPhone SDK?
For the sake of future viewers, I'm putting the answer to my own question since I haven't received a complete answer from anyone else.
First, you must have the right permissions, either "user_photos" or "friends_photos". Then you have to make sure that your test device updates your permissions -- I think restarting the device is what ultimately did it for me.
Once you've done that, you can get the JSON list of albums, after logging in via SSO, using this call:
[facebook requestWithGraphPath:#"me/albums" andDelegate:self];
This will give JSON array (under key data) with all kinds of information about each album, including the ID. To get a list of photos for a particular album ID (say its '123456789') do the following:
NSString * albumId = #"123456789";
NSString * path = [NSString stringWithFormat:#"%#/photos", albumId];
[facebook requestWithGraphPath:path andDelegate:self];
Your response will of course come via the FBRequestDelegate method request:didLoad where you can process the JSON data.
Download the FBGraph Api documents folder then add it to in your folder. and read the instruction on facebook developer site http://developers.facebook.com/docs/reference/api/.
This is the sample code - sample code
In this you will get a user profile pic in UIAlertView. You can show it where you want.

How to get face book contacts(email-id's) of friends for iphone

I am new to iphone, am trying to get the email-id's of friends from my face book account. I need to
save this contact info into my application and display in a UItableview . I am using graph api, using
this am able to get the friend's list,feeds metadata etc. But i want to fetch the contact info of all
my added friends. This is my code to fetch the friends list:
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:#"me/friends" withGetVars:nil];
NSLog(#"getMeFriendsButtonPressed: %#", fb_graph_response.htmlResponse);
The graph API me/friends will return you the list of friends which only has the friend's user ID and full name. As far as I know, it's not possible for you to retrieve your friends' email from an iPhone application.
And it looks like you're using the old library, try to download the latest FacebookConnect library from github. It's much simpler to use.

Publish message to friend's wall from iPhone app

I would like my iPhone app to be able to post a static message to a user's friend's facebook wall. Something like it shows the static message up above, and then a place to type in friends name and shows suggested friends. Is this done through graph api, or is there a key of permissions that the POST method can use?
Looks like this might be what you are after.
From the link:
"You just have to send your friend's Facebook ID as a parameter under the key "target_id".
set a parameter under the key #"target_id" on the parameters dictionary (when invoking dialog:andParams:andDelegate: on the Facebook object).
Here you have a sample post using the new sdk (the one that uses graph api):
NSMutableDictionary* params = [NSMutableDictionary dictionary];
[params setObject:#"Some text" forKey:#"user_message_prompt"];
[params setObject:#"another text" forKey:#"action_links"];
[params setObject:#"Yet another text" forKey:#"attachment"];
[params setObject:#"SOME FACEBOOK ID" forKey:#"target_id"];
//At some point you need to create the following Facebook instance
[facebook dialog: #"stream.publish"
andParams: params
andDelegate: self];
you first need to request the friend list and then provide an interface in your app where user could select which friend's wall he want to write on... :)
afterwards, you can pass the selected friends id to the dialog you are presenting to the user... Atleast I am used to do it this way and it seems to be a pretty standard way of publishing something on user's wall...
hope it helps

How to find Facebook Friends using the same app

I am creating an app and would like people using the app to find friends using the same app on Facebook. Any help on this would be great.
I know this can be done. I have seen it on Instagram and Tiger Woods 12.
Once you've authorised the user and obtained an access token, you can quickly determine which of their friends have already authorised your app with a call to /me/friends?fields=installed
For the users' friends who have already authorised the app, the result will look like this:
{
"installed": true,
"id": "{USER_ID_GOES_HERE}"
},
and for the users who have not already authorised the app, the result will look like this:
{
"id": "{USER_ID_GOES_HERE}"
},
If you're doing this in the iOS SDK you won't see that exact return value, but the SDK should put the results into a data structure you can use, and check for the presence of the 'installed' item
You can also request additional User object fields other than just 'installed', but this is just a quick example to show you how to get the list of friends that use the app
I have solved this problem in very easy way
Step 1= first download FbGraph API
Step 2= use this code for authentication
NSString *client_id = #"XXXXXXXXXXXXXX";// App id
//alloc and initalize our FbGraph instance
self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];
//begin the authentication process.....
[fbGraph authenticateUserWithCallbackObject:self andSelector:#selector(fbGraphCallback:)
andExtendedPermissions:#"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins"];
Step 3= Copy fbGraphCallback: Method from sample code and put in your controller
Step 4= Use this code to get Friends and it will give u the list of friend and who have same app install They look like
{
"installed": true,
"id": "{USER_ID_GOES_HERE}"
},
Code is =
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:#"installed" forKey:#"fields"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:#"me/friends" withGetVars:variables];
NSLog(#"getMeinstalled Friends: %#", fb_graph_response.htmlResponse);
Thats it!!!!!!!!
I know 'iphone' is tagged in the question, but still this answer might help others who will reach here:
The FQL query to get (just) the ids of all user's friends who are also users of the app is:
SELECT uid FROM user WHERE is_app_user=true AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

Problem getting friends events via FB connect

I'm trying to get the user's events and his friends events by the Graph API.
first, is there any other option getting all the friends events except sending new query for every one of them? (even if it exists in other protocols)
for( NSDictionary *friend in friends ) {
NSLog(#"sending events for %#", [friend objectForKey:#"id"]);
[facebook requestWithGraphPath:
[NSString stringWithFormat:#"%#/events&since=today&until=tomorrow&limit=10", [friend objectForKey:#"id"]]
andDelegate:self];
}
second, can I get ALL the user's events and not just what he has marked attendance status for?
Thanks!
First of all you have to take Extended Permission of user_events and friends events. As for as your second part of question is concerened you can query to event_member table to get status. hope it will work