How can I get user avatar link of facebook with userid - ios

I have id of user on facebook. Now I want to get user avatar base on the link https://graph.facebook.com on iOS.

Try to use via this link :
https://graph.facebook.com/user_id/picture?type=normal
Hope this works.

As i also gave you the first comment so explaining it.
If you looking the Avatar link try
http://graph.facebook.com/username/picture
where you can try the username like sunnyleone or you can use the facebook userid like for sunnyleone the userid is 131218490419638.
if you looking your facebook id you can get it from here. for your examples.
And One Major thing that nobody checked Image size is small for you can add parameter like
?type=normal
or for more bigger image. But the best one is you can replace the redirect link like.
replace _s to _n
Small Image :
http://profile.ak.fbcdn.net/hprofile-ak-prn1/t5/162024_131218490419638_623017319_s.jpg
Big Image : http://profile.ak.fbcdn.net/hprofile-ak-prn1/t5/162024_131218490419638_623017319_n.jpg
then you can get the bigger Image.
Hope this will help you

use #"https://graph.facebook.com/uid/picture" to get facebook profile picture

NSString *urlStr = [NSString stringWithFormat:#"http://graph.facebook.com/%#/picture?type=large", userId];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];

Related

Pass an Url to image view through AFNetworkingLibrary

The project was created with xcode 4.3.
I have used AFNetworking Library (non-ARC) in this app.
NSURL *url = [NSURL URLWithString:urlstring];
[exhibitPortraitImageView setImageWithURL:url];
Here, when I print a NSLog value, am getting the URL but the imageview is not displayed.
How can I solve this?
Your code is fine, problem is with URL.
Your URL, don't have prefix, http://, I added it and the code is same as in quesiton.
NSString *urlstring = #"http://mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg";
NSURL *url = [NSURL URLWithString:urlstring];
[exhibitPortraitImageView setImageWithURL:url];
Here, you've three options to fix this,
1) If URLs are not coming from server (or some where else) you can fix it within the app, see how,
NSString *badUrlString = #"mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg";
NSString *goodUrlString = [NSString stringWithFormat:#"http://%#",badUrlString];
2) Or if its coming from server (or some where else) you can ask them to fix this from their side.
3) If its under 2nd option then, ask them if this will always happen (static) then you can also modify this from your side if server side developers not able to fix.
see this for more help, Check string containing URL for "http://"
Yes,
I also tried your url, it is working fine.
I loaded it as:
NSURL *correctURL = [NSURL URLWithString:#"http://mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg"];
_imgFromUrl.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:correctURL]];
And the result,

Retrieve image from Google Maps in iOS

Im trying to attach a Google Maps image to an email generated in my app, however Google Maps does not return a specific image from its url. If I search a url with .png etc at the end of it, I can get the image fine, but how can I get the image from a site that doesn't have that,
ie:
http://maps.googleapis.com/maps/api/staticmap?size=200x200&maptype=roadmap\\&markers=size:mid%%7Ccolor:red%%7CNew+York&sensor=false
Im using NSData dataWithContentsOfURL: which then attaches to my email.
I have also tried to open the url in an iframe within the email with the same result, works with a .png url, not maps.
Any help would be greatly appreciated, thanks.
Try this,
NSString *urlString = #"http://maps.googleapis.com/maps/api/staticmap?size=200x200&maptype=roadmap\\&markers=size:mid%%7Ccolor:red%%7CNew+York&sensor=false";
NSString *encodedString=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *webURL = [NSURL URLWithString:encodedString];
NSData *myData = [NSData dataWithContentsOfURL:webURL];
UIImage *image = [[UIImage alloc] initWithData:myData];
self.imageView.image = image;
http://maps.googleapis.com/maps/api/staticmap?size=200x200&maptype=roadmap%%5C&markers=size:mid%%257Ccolor:red%%7CNew+York&sensor=false
Just needed to edit some of the % \ etc to incorporate the UTF8 encoding, however if you use the encoding method karthika suggested, it breaks the search. All I did was hard code the string and removed the added encoding before the address and its working perfectly.

Random URL website address from core data that holds a picture to display in UIImage in iOS?

I'm new to using xcode, so any information or links would be helpful. If I had a RANDOM website url in coredata, how would I be able to direct my UIImage to get the photo from that website to display in iOS?
Let's say imageURL is a NSString * ivar or property where you hold your URL.
To get the image this should work:
NSURL *url = [NSURL URLWithString:imageURL];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *myImage = [UIImage imageWithData: imageData];
Of course you should add some error checking but this should get you into the right direction.

iOS Facebook Graph API Profile picture link

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/

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.

Resources