Tag Friends in Facebook Photo Upload - objective-c

I'd like to be able to tag existing friends using the graph api:
Here's the code I have at the moment. The photo is being uploaded, but the photo isn't tagging the user specified in the user_id:
UIImage *testImage = [UIImage imageNamed:#"sendingTo"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:kFacebookFBConnectAppID, #"app_id",
testImage, #"source",
#"1381470076", #"message_tags",
#"TEST!", #"message", nil];
[self.socialIntegration.facebook requestWithGraphPath:[NSString stringWithFormat:#"/me/photos?access_token=%#", self.socialIntegration.facebook.accessToken]
andParams:params
andHttpMethod:#"POST" andDelegate:self];
Is the message_tags attribute not the correct attribute to use?
Thanks!
EDIT
From what I see here (https://developers.facebook.com/docs/reference/api/photo/#tags), it looks like I need to make three calls in total:
Post the Photo with the code I already have
Ask Facebook to give me the ID of this photo (which i can probably get from the FBRequestDelegate)
Tag People after posting.

ok, figured it out.
Here's how you do it.
First, you upload the image.
UIImage *testImage = [UIImage imageNamed:#"sendingTo"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:kFacebookFBConnectAppID, #"app_id",
testImage, #"source",
#"TEST!", #"message", nil];
[self.socialIntegration.facebook requestWithGraphPath:[NSString stringWithFormat:#"/me/photos?access_token=%#", self.socialIntegration.facebook.accessToken]
andParams:params
andHttpMethod:#"POST" andDelegate:self];
Next, upon successful upload, the - (void)request:(FBRequest *)request didLoad:(id)result method will return a dictionary result with 1 key id. That ID is the photoID of the photo you just uploaded, which you save into a string:
NSString *photoID = [NSString stringWithFormat:#"%#", [(NSDictionary*)result valueForKey:#"id"]];
Then make another GraphAPI request to tag your friends. In the code below I am tagging one specific friends, but to tag multiple friends use CSV string or array:
[self.socialIntegration.facebook requestWithGraphPath:[NSString stringWithFormat:#"%#/tags/%#?access_token=%#", photoID, #"1381470076", self.socialIntegration.facebook.accessToken]
andParams:nil
andHttpMethod:#"POST" andDelegate:self];

Related

How to tag users in a photo using the Facebook iOS SDK?

I can't seem to work out how to tag users in a Facebook photo upload.
The documentation seems to suggest that you use an array, but the following code doesn't parse correctly (causes an application crash)
- (void)uploadImage:(UIImage *)img
withTags:(NSArray *)tags
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"msgstring", #"message",
img, #"picture",
nil];
if (tags) {
[params setObject:tags
forKey:#"tags"];
}
self.requestType = FBAssistantRequestImageUpload;
[self.facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
It works fine without the tags. The array at the moment contains a single string with the identifier of the friend I wish to tag.
I assume I'm adding the tags incorrectly. I was hoping to avoid having to use the three-step method outlined here: Tag Friends in Facebook Photo Upload, as I believe that requires photos permission, which just posting the photo doesn't need.
here's the code I use to tag friends on photos:
NSMutableArray *tags = [[NSMutableArray alloc] init];
NSString *tag = nil;
if(self.selectedFriends != nil){
for (NSDictionary *user in self.selectedFriends) {
tag = [[NSString alloc] initWithFormat:#"{\"tag_uid\":\"%#\"}",[user objectForKey:#"id"] ];
[tags addObject:tag];
}
NSString *friendIdsSeparation=[tags componentsJoinedByString:#","];
NSString *friendIds = [[NSString alloc] initWithFormat:#"[%#]",friendIdsSeparation ];
[params setObject:friendIds forKey:#"tags"];
}

Facebook graph API : audio share

Can I share audio using facebook graphic API
Can I directly upload audio on facebook server like video?
Can I share audio link on facebook and it will show embedded player on facebook?
I have tried this solution ios Facebook Graph API - post Audio file , but it doesn't work as expected
What I tried is to share audio link http://bit.ly/Ok4ZX6 but show it on facebook like a normal link not with embedded player http://i.stack.imgur.com/Ld67c.png
Edit
Code I have use :
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:4];
[params setObject:text forKey:#"message"];
[params setObject:title forKey:#"name"];
[params setObject:fileUrl forKey:#"source"];
[facebook requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
Also used this code too :
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:4];
NSString *attachment = [NSString stringWithFormat:#"{'media': [{'type': 'mp3', 'src': '%#', 'title': '%#'}], 'messgae': 'Messgae Messgae Messgae', 'name': 'Name Name Name', 'href': '%#'}",amazon_link, title, link];
[params setObject:attachment forKey:#"attachment"];
[params setObject:text forKey:#"message"];
[params setObject:#"stream.publish" forKey:#"method"];
[facebook requestWithParams:params andDelegate:self];
What solution from that link did you try? Post your own code. I also noticed that your audio link doesn't work, atleast not for me.
I think the correct way is to use the "source" field in the graph api, not "link".
This is a good page on the developer reference:
http://developers.facebook.com/docs/reference/api/post/
To upload a video using the graph API you can do this. You also need to be authorized to the publish_stream permission.
NSString * file = [[NSBundle mainBundle] pathForResource:#"video" ofType:#"mov"];
NSData * video = [NSData dataWithContentsOfFile:file];
NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"title", #"title",
#"description", #"description",
video, #"video.mov",
#"video/quicktime", #"contentType",
nil];
[facebook requestWithGraphPath:#"me/videos"
andParams:dict
andHttpMethod:#"POST"
andDelegate:self];
Soundcloud use og:video tags to show the embedded player. The video tags accept SWF files, so it's possible to load up an interactive audio player widget. Try using the OG Debugger to see the tags.
Currently, this seems like the only strategy to show a player when content is shared.
Try like this.. Its working for me..
NSMutableDictionary *variables=[[NSMutableDictionary alloc]init];
//Posting audio file
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Dookudu" ofType:#"mp3"];
FbGraphFile *file=[[FbGraphFile alloc]initWithData:[NSData dataWithContentsOfFile:filePath]];
[variables setObject:file forKey:#"file"];
FbGraphResponse *response=[fbgraph doGraphPost:#"me/videos" withPostVars:variables];
NSLog(#"response %#",response.htmlResponse);

Sharing facebook dialog by using UIImage as #"picture"

Here is simple code
UIImage *ScreenShot = [self getScreenshot];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Name", #"name",
#"Caption.", #"caption",
#"Description.", #"description",
#"www.example.com", #"link",
ScreenShot, #"picture",
nil];
[ facebook dialog:#"feed"
andParams:params
andDelegate:self];
And when I compile it get this message
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x1288bb90' *** First throw call stack:
You can't directly upload an image to the wall, when publishing to the wall you can just link an image to it.
So, you need to upload the UIImage somewhere first. You have 2 options:
Upload to your/some server and publish a wall post linking to it.
Upload to a facebook album. Check the graph API about doing that, it is pretty straightforward
I just had a look at the Facebook API in order to see what you are doing here. To my mind, this
http://www.facebook.com/dialog/feed?
app_id=123050457758183&
link=http://developers.facebook.com/docs/reference/dialogs/&
picture=http://fbrell.com/f8.jpg&
name=Facebook%20Dialogs&
caption=Reference%20Documentation&
description=Using%20Dialogs%20to%20interact%20with%20users.&
redirect_uri=http://www.example.com/response
clearly says what Facebook wants you to do. Do you see that the picture parameter is not an image itself but a link to an image? You'll have to upload the image first and then put the Link to the image into this parameter.
I'm not sure if this is the only error in your code but it's a major one for sure.
Import an image into your project and try to change the line UIImage *ScreenShot = [self getScreenshot] to : UIImage *ScreenShot = [UIImage imageNamed:#"yourimage.png"];
If it works, you may probably have problem in your "getScreenshot" method.
I use this for my app :
UIImage *ImageView = [UIImage imageNamed:#"anImage.png"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
ImageView, #"picture",#"Name", #"name",
nil];
//Let's post it
[facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
-(void)request:(FBRequest *)request didLoad:(id)result{
if ([result objectForKey:#"id"]) {
UIAlertView *al = [[UIAlertView alloc] initWithTitle:#"MyApp" message:#"Your image has been posted on your wall!" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[al show];
[al release];
}
}

iPhone Facebook sdk, publish to wall

I got the following example form iPhone SDK sample code and probably tried 10 others but i cant seem to be able to post a message to my wall. I dont want a dialog popup to appear for me to enter my message, I want it so when the user click on a post button and the message will auto post to my wall. Im using the new version of Facebook iPhone SDK on iPad.
Id appreciate if someone can spot where im going wrong, at the moment i have no errors or warnings. The permissions i have in place are "email" and "publish_stream".
Thank you in advance.
Ive found App page on facebook if anyone is interested (http://www.facebook.com/settings/?tab=applications).
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"Always Running",#"text",#"http://itsti.me/",#"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
#"a long run", #"name",
#"The Facebook Running app", #"caption",
#"it is fun", #"description",
#"http://itsti.me/", #"href", nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Share on Facebook", #"user_message_prompt",
actionLinksStr, #"action_links",
attachmentStr, #"attachment",
nil];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(#"%#",[NSString stringWithFormat:#"%#/feed", [defaults objectForKey:USERID]]);
[facebook requestWithMethodName:[NSString stringWithFormat:#"%#/feed", [defaults objectForKey:USERID]]
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
If others stumble on this and wish to know how to remove the option so safari doesnt take over you screen, find the following and set safariAuth:NO.
[self authorizeWithFBAppAuth:YES safariAuth:YES];
You will also need to uncomment "return" from the following method so that the webpage doesnt expand out of its holder every time the user clicks between the input box and dismissing the keyboard.
(void)keyboardWillShow:(NSNotification*)notification

Post a picture on facebook

I want to publish a picture with a title (#name) and a texte (#caption) on facebook when my quiz is over.
I try to put my picture in an UIImage then i called her with #picture int the attachment but it doesn't work at all.
Have you a piece of code to show me how i can do this?
Thank you
Flo
This works for me :
- (void) uploadPhoto:(UIImage *) img caption:(NSString *) caption delegate:(NSObject<FBRequestDelegate> *) delegate{
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
if (caption != nil) {
[params setObject:params forKey:#"message"];
}
[self requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:delegate];
}
I think you have a typo in your method. I believe:
[params setObject:params forKey:#"message"];
should read:
[params setObject: caption forKey:#"message"];