Submitting a link via iPhone -> Facebook Connect - iphone

I'm trying to post links through the iPhone facebook connect without using the feed control. I want to simulate how the publish a story works on facebooks website, where I pass a link, and it returns back an image, story title, and a link. Right now I only know how to use the feed control, but I'm thinking there has to be a way to use possibly stream.Publish or showDialog, just not really sure which..
Anyone have any experience with this?

Use the facebook demo app.
in the SessionViewController, add this to get extended permission:
- (void)askPermission:(id)target {
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = #"publish_stream";
[dialog show];
}
Then you need a method to publish the stream. They don't say exactly what data to send. But whateer it is you package it in a dictionary. Since it is a URL, a good guess would be an NSString. You can get more from the API page
I found 5 that might work:
Feed.publishActionOfUser
Feed.publishStoryToUser
Feed.publishTemplatizedAction
Feed.publishUserAction
Also there is:
Links.post
But you'll have to figure it out, depending on what you want to do. You also need to kow the key. I picked url
- (IBAction)sendURL:(id)target{
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:urlString forKey:#"url"];
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:#"Links.post" params:args];
}
I've left some args out, but you get the idea. I;m not sure exactly what one you want, so you'll have to research the method calls.
Hope this helps.

Related

Share gifts with FB SDK iOS

I am having a problem making gifts (pack of coins, lives, etc). I have been using this guide.
I think I did everything correctly at https://developers.facebook.com/, created the coin type, made the object and used its id.
This is my code for request:
FBSDKGameRequestContent *gameRequestContent = [[FBSDKGameRequestContent alloc] init];
gameRequestContent.message = #"Take this coins";
gameRequestContent.title = #"Choose users";
gameRequestContent.filters = FBSDKGameRequestFilterAppUsers;
gameRequestContent.actionType = FBSDKGameRequestActionTypeSend;
gameRequestContent.objectID = #"386681778192859";
[FBSDKGameRequestDialog showWithContent:gameRequestContent delegate:self];
My question is how I can take a message or a callback from this request at another device. I was looking for a solution at facebook site, but I didn't find anything. In general, is it possible or do I have to make custom server?

Sharekit2.0 could not post together "URL-linked text, image" information to facebook wall

I'm upgrading from old sharekit to latest Sharekit2.0.
Ultimately I need to reach this on Facebookshare: https://s3-ap-southeast-1.amazonaws.com/eight29/demo.png
In old sharekit, I can do that by dialog.attachment (FBStreamDialog) as shown as below. However, in latest version, this function is missing.
BStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = #"Post Item to Facebook";
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"example\",\"href\":\"http://apps.facebook.com/example/?%d\",\
How can make it?
Thanks!
Liang
FBStreamDialog is not technically a part of ShareKit, but it belongs to Facebook-ios-sdk, which happens to be used in ShareKit.
FBStreamDialog no longer exists in FB's sdk, and other FBDialog family classes are deprecated. I suggest you to use their graph api, check "publishing" section for all possible parameters. Hopefully some will suit your purpose.
As for implementation, check SHKFacebook's - (void)doSend method. You can then subclass SHKFacebook and implement your own.

Error when posting to Facebook Wall from iPhone app

I'm building an app that allowed me to post to a user's wall on facebook. This functionality was working fine up until recently, when for some reason, if I try to post to the wall on facebook, I am now getting the error:
"The post's action links must be valid url's. You can see this because you are one of the developers of the app."
Does anyone know why this is happening? I did not change the code at all in my app, and after searching the web, found others are also having the same problem when trying to post to their facebook wall, but without a solution. Does anyone know what is wrong here, and how to fix it?
How old is the code that you are working with? And, are you using OAth 2.0? If you're not you should, because I believe OAuth 1.0 has been deprecated by Facebook and is only supported for "legacy" applications.
I found the solution to my problem. The relevant code that was causing the problem is:
- (void)postToWall {
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = #"Enter your message:";
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"Check out this great restaurant!\",\"href\":\"/\",\"caption\":\"%#\",\"description\":\"%# \r %#, %# %#\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.muslimgreenpages.ca/images/gethalal/GetHalal_IC_B_03.png\",\"href\":\"http://www.gethalalapp.com/\"}]}",
restaurantObj.name, restaurantObj.address, restaurantObj.city, restaurantObj.provinceState, restaurantObj.phoneNumber];
dialog.actionLinks = #"[{\"text\":\"Download GetHalal!\",\"href\":\"http://www.gethalalapp.com/\"}]";
[dialog show];
_posting = NO;
[_session logout];
}
In my dialog.attachment, I did not provide a value for the href parameter, so I simply removed it, and everything worked! Thanks very much mdominick for trying to help.
Take care.

How to do string formatting in Objective-C?

I am trying to post text from my iPhone app to my wall on Facebook. Everything works fine, however, my problem is that I am not sure how to format the text. I would like to show the user the name, address, city, state, and phone number of the restaurant they are viewing on the app. Here is my relevant code:
- (void)postToWall {
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = #"Enter your message:";
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"%# got straight A's!\",\"href\":\"http://www.example.com/\",\"caption\":\"%# must have gotten real lucky this time!\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.abc.png\",\"href\":\"http://www.example.com/\"}]}",
_facebookName, _facebookName];
dialog.actionLinks = #"[{\"text\":\"Download GetHalal!\",\"href\":\"http://www.example.com/\"}]";
[dialog show];
}
I would like to show the user the restaurant information in the dialog.attachment variable, such that the output on the facebook wall looks like this:
restaurant.name
restaurant.address
restaurant.city, restaurant.state
restaurant.phoneNumber
My problem is, the text above appears to be in JSON format. The restaurant object is available in the class, and I'd like to include it in the code above, but I don't know how. Can anyone show me how to do this?
Use a JSON library:
https://stackoverflow.com/questions/286087/best-json-library-to-use-when-developing-an-iphone-application
Also, check the Facebook sdk for iOS:
http://developers.facebook.com/docs/guides/mobile/#ios
The accepted answer in this StackOverflow post has the code you need, with JSONfragment:
How to post a message with attachment in Facebook?
(note that, in this case, the library used is http://code.google.com/p/json-framework/ )

How to give extended permissions in FBConnect with REST API in iPhone

I have developed an iPhone application, which is communicating data with faceBook. Initially I was only able to get basic information of user from Facebook. To post to a user's wall, I learnt about giving extended permission 'publish_stream', hence I added following code snippet:
- (void)session:(FBSession*)session didLogin:(FBUID)uid {
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = #"status_update";
[dialog show];
[self getFacebookName];
}
And made necessary changes in the FBPermissiondialog class file.
Now this is allowing me to post to my wall, but it shows two separate dialogs for permissions, first to access user's basic information, and second for publishing permission. I want to have all permissions in a single pop-up. Also, I am using FBRequest to post to Facebook, not FBStreamDialog (as I dont want the UI for posting).
Please help me with this, I badly need to resolve this issue soon.
Thanks in advance.
In FBLoginDialog.m file
- (void)loadLoginPage {
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"1", #"fbconnect", #"touch", #"connect_display", _session.apiKey, #"api_key",
#"fbconnect://success", #"next",#"user_photos,photo_upload",#"req_perms",nil];
[self loadURL:kLoginURL method:#"GET" get:params post:nil];
}
add "req_perms" key to the dictionary as shown above.
Hope this will solve your problem :)