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];
}
}
Related
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);
So I'm creating an iPhone app that needs to be able to upload a photo when the user checks into a location using the Facebook Graph API.
Right now my code is this:
if (![delegate.facebook isSessionValid])
[delegate.facebook authorize:[NSArray arrayWithObjects:#"publish_stream", #"offline_access", #"publish_checkins", nil]];
parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:[placeDictionary objectForKey:#"id"] , #"place",
serialisedCoordinates, #"coordinates",
message, #"message",
pickedImage, #"picture",
#"Via the official REDACTED app", #"application", nil];
[delegate.facebook requestWithGraphPath:#"me/checkins" andParams:parameters andHttpMethod:#"POST" andDelegate:fbCheckInResultHandler];
Where 'pickedImage' is the UIImage returned from a UIImagePickerController.
Even when I pick an image (i.e., pickedImage != nil), no picture is uploaded when checked in. The check in appears on Facebook with the message, coordinates and app information, just no image.
Really hope someone can help.
Cheers,
Kiran
Here is the whole function that is being called when a checkin is made:
-(void)fbPostCheckInWithMessage:(NSString *)message andFriends:(NSArray *)friends {
if (![delegate.facebook isSessionValid]) {
NSLog(#"Session invalid");
[delegate.facebook authorize:[NSArray arrayWithObjects:#"publish_stream", #"offline_access", #"publish_checkins", nil]];
} else {
NSLog(#"Session valid");
}
NSMutableString *friendsIDString;
friendsIDString = [NSMutableString stringWithFormat:#"%#", [[friends objectAtIndex:0] userID]];
if ([friends count] > 1) {
for (User *f in taggedFriends) {
if (f != [taggedFriends objectAtIndex:0]) {
[friendsIDString appendString:[NSString stringWithFormat:#", %#", f.userID]];
}
}
}
NSLog(#"Tagged Friends: %#", friendsIDString);
SBJSON *jsonWriter = [SBJSON new];
NSMutableDictionary *locationDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:#"%f", userLocation.coordinate.latitude], #"latitude",
[NSString stringWithFormat:#"%f", userLocation.coordinate.longitude], #"longitude", nil];
NSString *serialisedCoordinates = [jsonWriter stringWithObject:locationDictionary];
NSData *pictureData = UIImagePNGRepresentation(pickedImage);
NSLog(#"picture: %#", pictureData);
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:[placeDictionary objectForKey:#"id"] , #"place",
serialisedCoordinates, #"coordinates",
pictureData, #"message",
pickedImage, #"picture",
#"Via the official REDACTED app", #"application", nil];
[delegate.facebook requestWithGraphPath:#"me/checkins" andParams:parameters andHttpMethod:#"POST" andDelegate:fbCheckInResultHandler];
}
I am using the friendsIDString to get the IDs of the friends the user with. I've removed this functionality from the example here because it was all commented out because I was trying to isolate what was causing the problem (which was the photo tagging). Just wanted to clear that up.
--UPDATE--
Here's how I'm setting pickedImage. I use the delegate methods from the UIImagePickerController:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
NSLog(#"Picked image");
pickedImage = [[UIImage alloc] init];
pickedImage = image;
[imagePickerController dismissModalViewControllerAnimated:YES];
}
You can upload photos to facebook using :- UIImagePNGRepresentation,UIImageJPEGRepresentation,etc based on type of image or imagewithdata from UIImage class..
NSData *yourImageData= UIImagePNGRepresentation(yourImage);
Initialize the dictionary :-
NSMutableDictionary *mutableDictWithParam= [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Your text", #"message", yourImageWithData, #"theSource", nil];
finally send post :-
[facebook requestWithGraphPath:#"/me/photos" andParams:mutableDictWithParam andHttpMethod:#"POST" andDelegate:self];
In you app i think you have not initialized your NSData object(pickedimage) ..else everything seems fine.
As Per Our Discussion You can use this to compress image:-
NSData* UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality);
NSData *compressedImage = UIImagePNGRepresentation(yourIMage, .5)//quality is ensured through second argument lies between o and 1
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];
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
I can use the Facebook iPhone API to authorize and publish posts, but I want the textbox on the dialogue view bigger, to display more text, instead of only showing 2 lines, as the screenshot:
Anybody know how to make this textbox bigger? Does it have to change the Facebook API code?
If the textbox is supposed to be short as the title of the wall post, how to send the App icon and more text underneath the textbox as shown in the screenshot? (I only know how to publish the text in the textbox for the moment)
Regarding the text under your image, you can check the demo provided with the iOS library. For examle, the part that uploads that text can be found at this file:
- (IBAction) publishStream: (id)sender {
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:
kAppId, #"api_key",
#"Share on Facebook", #"user_message_prompt",
actionLinksStr, #"action_links",
attachmentStr, #"attachment",
nil];
[_facebook dialog: #"stream.publish"
andParams: params
andDelegate:self];
}
If you want to add an image at this post as well, try
NSDictionary* media = [NSDictionary dictionaryWithObjectsAndKeys:
#"image", #"type",
#"your.image/url.png", #"src",
#"http://www.alink.org", #"href",
nil];
and then you should add this to your attachment NSDictionary:
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
#"a long run", #"name",
#"The Facebook Running app", #"caption",
#"it is fun", #"description",
[NSArray arrayWithObjects:media, nil ], #"media",
#"http://itsti.me/", #"href", nil];
You can check some guidelines for stream attachements at this link.
I hope that helps!