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
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);
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];
}
}
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 know this has been asked a lot here, but none of the answers seem to work for me :(
I'm trying to post text to the users Facebook wall from my iPhone app. I already have the Facebook delveloper stuff set up, and almost everything is working. Almost.
facebook = [[Facebook alloc] initWithAppId:#"123813234381280"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"]
&& [defaults objectForKey:#"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:#"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:#"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
NSArray* permissions = [[NSArray arrayWithObjects:
#"publish_stream", nil] retain];
[facebook authorize:permissions delegate:self];
}
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"123813234381280", #"app_id",
#"http://test.com/", #"link",
#"Test-Name", #"name",
//#"Reference Documentation", #"caption",
#"Download the app NOW from the App Store", #"description",
#"Test-Message", #"message",
nil];
[facebook dialog:#"feed" andParams:params andDelegate:self];
Now there appears a dialog, but the textfield where it should say "Test-Message" in it is empty. You know, the one where it says what to post on the wall. Everything else works, the description, the link, the name. Everything besides the message.
Can anybody help me?
Facebook is now ignoring the message parameter:
http://developers.facebook.com/blog/post/510/
message : This field will be ignored on July 12, 2011 The message to
prefill the text field that the user will type in. To be compliant
with Facebook Platform Policies, your application may only set this
field if the user manually generated the content earlier in the
workflow. Most applications should not set this.
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!