Getting image from gallery of Facebook and show it in iPhone - iphone

I want get image from public perfil of Facebook and show it in my iPhone. I'm using the Facebook Developer method "getPhoto" but I canĀ“t show any image?
Can someone help me?

NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
As told Previously your problem to retrieve the object id. Here is the solution:-
To retrieve the images of your friend. Create the connection with the url
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/me/friends?access_token=%#",accessTokenValue];
above url when hit returns an array of dictionary in which name of your friend and his id is written. Just Json parse that you will get the id of the person.

you need to use graph api for this purpose
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];

Related

Post image from local machine to user wall of Facebook

How can i post images using slRequest to Facebook user wall ?
-(IBAction)done
{
NSString *message=#"hello";
NSString *picture=[[NSBundle mainBundle]pathForResource:#"4" ofType:#"jpg"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:message, #"message",picture,#"picture", nil];
}
Try to use this one and you know you are getting path from NSBundle not image so you need to get first image from picture path and then do it.
NSString *picture=[[NSBundle mainBundle]pathForResource:#"4" ofType:#"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:picture];
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:message, #"message",image, #"picture",nil];
try this,use #"source" key for post image
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:_image, #"source",msg,#"name",nil];
//_image is UIImage

iPhone NSMutableArray loading background image from url

I have a NSMutableArray where it stores url to a image. And this NSMutableArray is called userPic. From my server it only prints out the url: not JSON or anything, only the url.
I can see in the output in Xcode that it shows the url, but how to I get this url in userPic to a background? Im trying to addSubView with the image for a background.
If something is unclear, sorry about that. Just let me know.
Please try to use this one.And i think your URL at index 0 of your array.
NSURL *imgURL = [NSURL URLWithString:[userPic objectAtIndex:0]]; // put your particular index where your image url in your array...
NSData *imgData = [[NSData alloc]initWithContentsOfURL:imgURL];
UIImage *img = [UIImage imageWithData: imgData];
[newView setBackgroundColor:[UIColor colorWithPatternImage:img]]

how can I display UIImage from image url

The code below works fine if I give statically but
imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:#"http://4cing.com/mobile_app/uploads/pageicon/6.jpg"]]]];
Same code - I am passing the image url name dynamically it's not working
imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:#"%#",[imagename objectAtIndex:0]]]];
You need to verify the NSArray contents. Log out the objects of the array:
NSLog(#"imagename = %#",[imagename description]);
Also, a side-note - might want to think about loading that image dynamically. I wrote a class that makes this pretty painless:
https://stackoverflow.com/a/9786513/585320
The answer is geared toward using in TableViews (where lag would really hurt performance), but you can (and I do) use this for any web image loading. This keeps the UI fluid and is very fast.
NSMutableArray *imagename = [[NSMutableArray alloc] initWithObjects:#"http://4cing.com/mobile_app/uploads/pageicon/6.jpg", nil];
UIImageView *imgDescView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 200, 200)];
imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:#"%#",[imagename objectAtIndex:0]]]]];
it is working ... i think u r not creating array properly.
Hi create url in this manner
[NSURL URLWithString:[[NSString stringWithFormat:#"%#",[imagename objectAtIndex:0]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
i think it will work and will resolve ur problem.

iPhone App: how to get app icon from app id?

I am looking for a way to get the app icon from the app id. Do you know how to do it? Please share the way. Thanks.
e.g
Instagram, where the id I'm looking for is: id389801252
https://itunes.apple.com/jp/app/instagram/id389801252?mt=8
I want to get this image:
(I composed this answer after 2 minutes of googling... It's just the matter of the correct keyword!)
This is possible using an undocumented documented API of the iTunes Store. It might change in the future, but it doesn't seem to have changed in the near past, so here you are...
NSString *idString = #"id389801252";
NSString *numericIDStr = [idString substringFromIndex:2]; // #"389801252"
NSString *urlStr = [NSString stringWithFormat:#"http://itunes.apple.com/lookup?id=%#", numericIDStr];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *json = [NSData dataWithContentsOfURL:url];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:json options:0 error:NULL];
NSArray *results = [dict objectForKey:#"results"];
NSDictionary *result = [results objectAtIndex:0];
NSString *imageUrlStr = [result objectForKey:#"artworkUrl100"]; // or 512, or 60
NSURL *artworkURL = [NSURL URLWithString:imageUrlStr];
NSData *imageData = [NSData dataWithContentsOfURL:artworkURL];
UIImage *artworkImage = [UIImage imageWithData:imageData];
Note that this performs two synchronous round-trips using the NSURL API, so you better wrap this in a backgorund thread for maximal user experience. Feed this program an ID string (idString in the code above) and in the end, artworkImage will contain a UIImage with the desired image.
Just for reference, you can use the app's bundle id too:
http://itunes.apple.com/lookup?bundleId=com.burbn.instagram
Not sure if this is at all relevant anymore, but Apple provides an iTunes Link Maker tool. If you use this tool to find your app, you'll also see where it shows an App Icon section. Click embed and grab the img link from there. One thing to note, I did end up playing with the url a bit to find the right size and format I needed (for instance you can get a jpg render instead of png or select an arbitrary size like 128x128)

how to fetch image from array and show it on table view

I am fetching image from server and save it on a NSMutableArray. The result of array like that
myarray={"roger_50.jpg",....};
Now i dont know how to access this image on table view.
Just have proper URL for image in array. And pass it to NSURL object as a link.
NSURL *imageURL = [NSURL URLWithString:[myarray objectAtIndex : yourindex]];
NSData *data = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [[UIImage alloc] initWithData:data];
Have a nice coding.
Stay Hungry, Stay Foolish...
i hope the thing you are getting from array are only the names you can retrieve images from server in only two ways i) in nsdata ii)by url of the images on sever .By this way you cann't access the images.