iOS Facebook Graph API Profile picture link - ios

I am trying to retrieve the link to the profile picture...
So far the graph API call :
[facebook requestWithGraphPath:#"me/picture" andDelegate:self];
returns the image itself as Data. When I make the call :
[facebook requestWithGraphPath:#"me/picture" andDelegate:self];
I do get an array of picture with the link for each of them.
Is there anyway to get some sort of similar thing for the profile pic, at least just the link... Or is it not possible?
If someone has already been through this please let me know.
Cheers,
Sami.

make the graph request:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"picture",#"fields",nil];
[facebook requestWithGraphPath:#"me" andParams:params andDelegate:self];
then on request didLoad:
NSString *pictureUrl = [result objectForKey:#"picture"];
If you want additional fields, just add them to the params dictionary:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"id,name,picture",#"fields",nil];

After logged in you can get the profile picture with this link;
https://graph.facebook.com/userId/picture?width=640&height=640

Do you meen anything like the following?
NSString *fbuid = #"1234567890";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture", fbuid]];
Or do you need the final url to which the link above redirects you? For the final url I guess you will need a proxy, something of this kind maybe.
UPDATE:
You can also get the link with FQL:
https://developers.facebook.com/blog/post/2012/04/11/platform-updates--operation-developer-love/

Related

Twiiter API failed to get followers and following details

I want to get the twitter followers and following person details. i know that not present any direct mechanism to get all the detail. so i first get the id's of all friends. i used this API to get the id's.
NSURL * requestAPI =[NSURL URLWithString:#"https://api.twitter.com/1.1/friends/ids.json"];
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:twitterAccount.username, #"screen_name", nil]; // Fo rthis Api you need to pass these parmeter is necessary
and pass this parameter and get the list of id's.
and using that ids i want to get the all details about friends. so i tried this API
NSURL * requestAPIForNames =[NSURL URLWithString:[NSString stringWithFormat:#"https://api.twitter.com/1.1/users/lookup.json?user_id=%#",result]];
NSMutableDictionary *parameters1 = [[NSMutableDictionary alloc] init];
[parameters1 setObject:#"xxxxxxxxxxxxxxxxxxxx" forKey:#"oauth_consumer_key"];
[parameters1 setObject:#"xxxxxxxxxxxxxxxxxxxxxxxx" forKey:#"oauth_consumer_secret"];
i have pass the all id's to this API. and want to get the details of followers. but not sucess.
i get the following issue.
{
errors = (
{
code = 32;
message = "Could not authenticate you";
}
);
}
why this happening can anyone help me to do this.
thanks in advance.

Facebook SDK loads default image and not image from my profile, why?

I've got these facebook permissions set in my app:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"user_games_activity",
#"friends_games_activity",
#"publish_actions",
#"user_photos",
nil];
[[myDelegate facebook] authorize:permissions];
I'm making a request like so :
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"name,picture",#"fields",nil];
[[delegate facebook] requestWithGraphPath:#"me" andParams:params andDelegate:self];
And handling the response like :
else if([request.url rangeOfString:#"me"].location != NSNotFound)
{
NSString *username = [result objectForKey:#"name"];
NSLog(#"We think the username is %#", username);
helloGreeting.text = [NSString stringWithFormat:#"Hello %#", username];
NSString *pictureUrl = [result objectForKey:#"picture"];
NSLog(#"Now loading image [%#]", pictureUrl);
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:pictureUrl]];
profilePhoto.image = [UIImage imageWithData:data];
}
The log output I get is :
2012-06-26 15:10:49.002 FacebookIntegrator[10549:f803] We think the username is James Elsey
2012-06-26 15:10:49.003 FacebookIntegrator[10549:f803] Now loading image [http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yo/r/UlIqmHJn-SK.gif]
Question : Why does it obtain a default generic facebook icon rather than my own profile picture? Using the same access tokens on the Graph Explorer I can get to my profile picture image URL
The documentation for user_photos states :
Provides access to the photos the user has uploaded, and photos the
user has been tagged in
User profile picture do not require user_photos permissions. Picture is likely coming from facebook cache, you should use following url for picture.
http://graph.facebook.com/<facebook id>/picture

Add Image to Facebook Wall

I am trying to implement a previous answer. Here is the code recommended:
-(void) postImageToFB:(UIImage *) image
{
NSData* imageData = UIImageJPEGRepresentation(image, 90);
Facebook* fb = [(uploadPicAppDelegate *)[[UIApplication sharedApplication] delegate] facebook ];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[fb accessToken],#"access_token",
#"message text", #"message",
imageData, #"source",
nil];
[fb requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
But I am getting a error not found on the term: uploadPicAppDelegate
I can't find this in the Facebook sdk or a search of the web (other than additional similar code). Is this a custom created data type --or -- am I missing a file that needs to be imported?
Thanks.
In your params dictionary the value for #"source" should be a link for the picture and not a NSData object.

iOS & Facebook: upload an image along with user comment to the wall

I have an app, it takes screenshot of itself and I would like to post it on user's wall along with a comment.
The problem is, I seemingly tried every option and none of it works:
[facebook dialog:#"feed" ...] doesn't work because you can supply only a URL, not a UIImage.
[facebook requestWithGraphPath ...] doesn't work because the user is not prompted for the comment.
I could first (silently) try to upload the screenshot with requestWithGraphPath and then feed its newly created URL to dialog which doesn't work because of "FBCDN image is not allowed in stream". All of this is of course using callbacks which, including login callback, makes for nice big mess.
I even tried ShareKit but forgot about it after the app strangely could/couldn't login.
Please, how can I share both an image and a comment?
If you are using facebook's latest iOS SDK, in Hackbook sample app, look for APICallsViewController.m file. There is this method that you can post using UIImage directly:
/*
* Graph API: Upload a photo. By default, when using me/photos the photo is uploaded
* to the application album which is automatically created if it does not exist.
*/
- (void) apiGraphUserPhotosPost {
NSString *sourcePath = [[NSBundle mainBundle] resourcePath];
NSString *file1 = [sourcePath stringByAppendingPathComponent:#"/MP1101frame1002.jpg"];
UIImage *img = [[[UIImage alloc]initWithContentsOfFile:file1]autorelease];
[self showActivityIndicator];
currentAPICall = kAPIGraphUserPhotosPost;
HackbookAppDelegate *delegate = (HackbookAppDelegate *) [[UIApplication sharedApplication] delegate];
// Download a sample photo
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
// UIImage *img = [[UIImage alloc] initWithData:data]; //here you can insert your UIImage
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
yourMessageHere, #"message", //whatever message goes here
img, #"picture", //img is your UIImage
nil];
[[delegate facebook] requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
If you haven't already, you may want to try the latest development branch of ShareKit at this address:
https://github.com/Sharekit/Sharekit
It has significant improvements added by the community over the canonical version.

Adding a share link when using fbdialog to post to a users wall

I'm using FBConnect to post a link to a user's wall. I am using the FBDialog api instead of using graph paths:
[facebook dialog:#"feed" andParams:_params andDelegate:_delegate];
Everything posts correctly except when the wall is viewed, there is no share link, only the like and comment links. I've researched this and figured out that this appears to be unique to using FBDialog.
If the graph path method is used:
[facebook requestWithGraphPath:_path andParams:_params andHttpMethod:#"POST" andDelegate:_delegate];
the share link shows up.
To fix this, I have added a custom link using the actions parameter provided by FBDialog:
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* actionLinks = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
#"Share", #"name",
#"http:???", #"link",
nil],
nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
[params setObject:#"link" forKey:#"type"];
[params setObject:self.url forKey:#"link"];
[params setObject:self.title forKey:#"name"];
[params setObject:self.caption forKey:#"caption"];
[params setObject:actionLinksStr forKey:#"actions"];
This again, works correctly and creates a share link. The question I have is: What url do I use to share the wall post? Any ideas?
Thanks so much!

Resources