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
Related
I have been trying to extract metadata information from a .mp3 file for an iPhone app. I tried using AVAsset like this.It didn't work,the common meta data is empty. But audacity and another iOS app from app store could retrieve the meta data details. I don't know why?.
So, I tried to extract the same with below code using AudioToolBox framework
CFDictionaryRef piDict = nil;
UInt32 piDataSize = sizeof(piDict);
// Populates a CFDictionary with the ID3 tag properties
err = AudioFileGetProperty(fileID, kAudioFilePropertyInfoDictionary, &piDataSize, &piDict);
if(err != noErr) {
NSLog(#"AudioFileGetProperty failed for property info dictionary");
return nil;
}
// Toll free bridge the CFDictionary so that we can interact with it via objc
NSMutableDictionary* nsDict = [(__bridge NSDictionary*)piDict mutableCopy];
This returned everything except album art. When I tried to extract the album art using kAudioFilePropertyAlbumArtwork , I got osstatus error(The operation couldn't be completed).
So at last, I tried my luck with ObjC wrapper for libId3(found here). It worked perfectly well. I could get the artwork.
My question is, why AVAsset could not retrieve the data?. What am I missing there?. somebody managed to to get it work?. A sample will be appreciated.
Why kAudioFilePropertyAlbumArtwork extraction couldn't be completed?. Both the issues happened with all the .mp3 files I had.
Solution Update:
AVAsset didn't work for me because I made my URL using
[NSURL URLWithString:[filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
rather than
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
To use AVAsset to extract metadata informations, this post is useful. The following code is what you need:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"filename" ofType:#"mp3"];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
AVAsset *asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
NSArray *keys = [NSArray arrayWithObjects:#"commonMetadata", nil];
[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
NSArray *artworks = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata
withKey:AVMetadataCommonKeyArtwork
keySpace:AVMetadataKeySpaceCommon];
for (AVMetadataItem *item in artworks) {
if ([item.keySpace isEqualToString:AVMetadataKeySpaceID3]) {
NSDictionary *dict = [item.value copyWithZone:nil];
self.imageView.image = [UIImage imageWithData:[dict objectForKey:#"data"]];
} else if ([item.keySpace isEqualToString:AVMetadataKeySpaceiTunes]) {
self.imageView.image = [UIImage imageWithData:[item.value copyWithZone:nil]];
}
}
}];
NSURL *fileURL1 = [NSURL fileURLWithPath:url];
AVAsset *asset = [AVAsset assetWithURL:fileURL1];
for (AVMetadataItem *metadataItem in asset.commonMetadata) {
if ([metadataItem.commonKey isEqualToString:#"artwork"]){
NSDictionary *imageDataDictionary = (NSDictionary *)metadataItem.value;
NSData *imageData = [imageDataDictionary objectForKey:#"data"];
UIImage *image = [UIImage imageWithData:imageData];
imageThumb.image = image;
}
}
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)
I can't seem to properly retrieve a user's profile picture using the current iOS graph method.
My call: self.pictureRequest = [facebook requestWithGraphPath:#"me/picture" andDelegate:self];
What I do with the result:
-(void)request:(FBRequest *)request didLoad:(id)result{
if(request == self.pictureRequest){
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
image.image = [UIImage imageWithData:result];
[self.view addSubview:image];
NSLog("result is %#", result);
}
So I'm just trying to get the profile picture right now. Result shows up as null in the console. I guess this means I'm not actually getting a result? (I tried if(result) NSLog(#"got a result") but it doesn't return, so I'm guessing a result isn't being sent back by fb?)
Any ideas? I also looked up a similar problem here but not sure what they do differently:
Problem getting Facebook pictures via iOS
well I can retrieve the user pic and other info like this .. try it
- (void)fetchUserDetails {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"SELECT uid, name, pic, email FROM user WHERE uid=me()", #"query",nil];
[fb requestWithMethodName:#"fql.query"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}//Call this function after the facebook didlogin
and in request didLoad:
- (void)request:(FBRequest *)request didLoad:(id)result
{
if([request.url rangeOfString:#"fql.query"].location !=NSNotFound)
{
if ([result isKindOfClass:[NSArray class]] && [result count]>0) {
result = [result objectAtIndex:0];
}
if ([result objectForKey:#"name"]) {
self.fbUserName = [result objectForKey:#"name"];
// Get the profile image
UIImage *fbimage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result objectForKey:#"pic"]]]];
}
If you want to get the picture URL using requestWithGraph path (instead of requestWithMethodName like #Malek_Jundi provides) then see my answer here:
iOS Facebook Graph API Profile picture link
You can also get fb profile picture url by,
NSString *userFbId;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture", userFbId]];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:url];
self.userProfileImage.image = [UIImage imageWithData:imageData];
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]]];
Here Iam having a problem.Actually I implemented the facebook integration in my application and I need to post the images with text but I dont have any idea how to work on this.can anyone suggest this with a sample code so that it is very helpful for me.
Anyone's help will be much appreciated.
I assume that you want to draw some text in an image, and then upload the image to Facebook.
At first, we need to draw the original image and the desired text into a new image.
UIGraphicsBeginImageContext(CGSizeMake(320.0, 320.0));
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw the original image
[image drawInRect:CGRectMake(0, 0, 320.0, 320.0)];
// Draw the text
[#"text" drawInRect:CGRectMake(...) withFont:[UIFont systemFontOfSize:20.0];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
And then, convert the image into NSData and call Facebook's "photos.upload" API to upload it.
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:#"caption" forKey:#"caption"];
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
NSData *data = UIImagePNGRepresentation(newImage);
[uploadPhotoRequest call:#"photos.upload" params:args dataParam:data];
If you want to upload the images to your server, and post a small story to Facebook's wall. Use the stream API.
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = #"Prompt";
NSString *name = #"Your caption";
NSString *src = #"http://example.com/path/of/your/image";
NSString *href = #"http://what/happens/if/the/user/click/on/the/image";
NSString *attachment = [NSString stringWithFormat:#"{\"name\":\"%#\",\"media\":[{\"type\":\"image\", \"src\":\"%#\", \"href\":\"%#\"}]}", name, src, href];
dialog.attachment = attachment;
[dialog show];
Maybe you would be happy using BMSocialShare. It's a simple lib I wrote.
BMFacebookPost *post = [[BMFacebookPost alloc]
initWithTitle:#"Simple sharing via Facebook, Email and Twitter for iOS!"
descriptionText:#"Posting to Facebook, Twitter and Email made dead simple on iOS. Simply include BMSocialShare as a framework and you are ready to go."
andHref:#"https://github.com/blockhaus/BMSocialShare"];
[post setImageUrl:#"http://www.blockhausmedien.at/images/logo-new.gif"
withHref:#"http://www.blockhaus-media.com"];
[[BMSocialShare sharedInstance] facebookPublish:post];