Facebook graph API : audio share - objective-c

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);

Related

How to upload a file using Reskit in iOS

How would I go about uploading an audio file using Restkit? I've looked around the documentation and can't seem to find anything about uploading files. Thanks for your help.
This article explains how: http://mobile.tutsplus.com/tutorials/iphone/advanced-restkit-development_iphone-sdk/
Excerpt:
NSString* myFilePath = #"/some/path/to/picture.gif";
RKParams* params = [RKParams params];
// Set some simple values -- just like we would with NSDictionary
[params setValue:#"Blake" forParam:#"name"];
[params setValue:#"blake#restkit.org" forParam:#"email"];
// Create an Attachment
RKParamsAttachment* attachment = [params setFile:myFilePath forParam:#"image1"];
attachment.MIMEType = #"image/gif";
attachment.fileName = #"picture.gif";
// Attach an Image from the App Bundle
UIImage* image = [UIImage imageNamed:#"another_image.png"];
NSData* imageData = UIImagePNGRepresentation(image);
[params setData:imageData MIMEType:#"image/png" forParam:#"image2"];
// Let's examine the RKRequestSerializable info...
NSLog(#"RKParams HTTPHeaderValueForContentType = %#", [params HTTPHeaderValueForContentType]);
NSLog(#"RKParams HTTPHeaderValueForContentLength = %d", [params HTTPHeaderValueForContentLength]);
// Send a Request!
[[RKClient sharedClient] post:#"/uploadImages" params:params delegate:self];
Enjoy!
For Restkit 0.20, the MIME types are automatically detected when creating the attachement. So you do not need to call
attachment.MIMEType
And when building the params:
[params setData:imageData MIMEType:attachment.MIMEType forParam:#"image2"];
see this link

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"];
}

Tag Friends in Facebook Photo Upload

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];

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

How to make the textbox in the Facebook dialogue view bigger, and show App brief?

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!