How to share to Facebook (iOS) - ios

I'm trying to share a photo to Facebook using the Open Graph API. I was unsure of how to share a photo so I'm starting off with code to just post a like. So far I have the following code:
// Create an object
NSDictionary *properties = #{
#"og:type": #"myObject",
#"og:title": #"title",
#"og:description": #"description",
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"og.likes";
[action setObject:object forKey:#"myObject"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"myObject";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
I created a custom graph object on Facebook "myObject" and am trying to share or like this publicly on Facebook. I would love any help on this, when this code runs nothing shows up. Ideally I would like to add a photo to this object and be able to share it with a callback link to either my site (and eventually the app)!

try to use shareSDK~ it's nice
link: http://www.mob.com/en

You should go to open graph on facebook app and get code sample facebook auto generate:
Dashboard
Code autogenerate

Related

Local UIImage not show in open graph story Facebook

I'm try to publish a local photo in a Facebook open graph story, but the image is not appears.
This code is the same of the documentation page of Facebook developers. facebook_developers open graph ios
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [UIImage imageNamed:#"coffee-and-sunrise.jpg"];
// Optionally set user generated to YES only if this image was created by the user
// You must get approval for this capability in your app's Open Graph configuration
// photo.userGenerated = YES;
// Create an object
NSDictionary *properties = #{
#"og:type": #"books.book",
#"og:title": #"A Game of Thrones",
#"og:description": #"In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.",
#"books:isbn": #"0-553-57340-3",
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"books.reads";
[action setObject:object forKey:#"books:book"];
// Add the photo to the action. Actions
// can take an array of images.
[action setArray:#[photo] forKey:#"image"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"books:book";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
Facebook is aware this is broken on iOS and has marked it as "won't fix". Incredibly agitating, please do voice your concern on the bug report they've acknowledged here.

Facebook Open Graph Story- caption and app link with user generated photo

I am trying to publish an open graph story containing an App Link.
I set up my story with the following code-
NSDictionary *properties = #{
#"og:type": #"bcskitracker:tour",
#"og:title": tour.route.name,
#"og:distance": [tour.distance stringValue],
#"og:vertical": [tour.ascent stringValue],
#"og:description": #"description",
#"og:url": #"https://fb.me/786890254772699",
#"og:image": photo
};
FBSDKShareOpenGraphObject *tourObject = [FBSDKShareOpenGraphObject objectWithProperties:properties];
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"bcskitracker:ski";
[action setObject:tourObject forKey:#"bcskitracker:tour"];
[action setString:#"true" forKey:#"fb:explicitly_shared"];
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"bcskitracker:tour";
[FBSDKShareAPI shareWithContent:content delegate:self];
If the photo is marked as userGenerated:NO, the story is published as expected with a caption and if you tap the post it opens the iPhone app:
However only one photo can be displayed and appears very small on the iPhone. If I mark the photo as userGenerated:YES the post displays the large photo, however there is no caption and no app link (only a link to facebook's app directory)-
The post doesn't even display the tour title as constructed in the story template-
Is there any way to include the caption and app link with a user generated photo? I understand I can set the action.message but this is restricted and doesn't link to the app.
This is currently intended behaviour; if you set a photo attachment as user_generated = yes, it's considered as a photo upload. In that case, you can't mix in Open Graph information. So it's one of the two :)
What you could do, is to generate a single image on your server side with both the map and uploaded photo. If you use that as your og:image, it will be included in the post.

Create a fitness run with the Open Graph API in iOS without GPS-data

I want to share a fitness run via the Open Graph API.
For me it is most important to display the distance and the duration in the top line of the post right beside the name of the user, along with a description text. (So maybe my idea to use the fitness:runs action instead of a custom action is wrong?)
I tried several solutions from StackOverflow, but none of them use the 'FBSDKShareOpenGraphAction' with the 'FBSDKShareDialog', so I modified it a bit. This is my code so far:
// Create the object
NSDictionary *courseDict = #{
#"og:type": #"fitness:course",
#"og:title": #"Run",
#"og:description": #"Run",
#"fitness:duration:value": #"300",
#"fitness:duration:units": #"s",
#"fitness:distance:value": #"1.2",
#"fitness:distance:units": #"km",
#"fitness:speed:value": #"13.2",
#"fitness:speed:units": #"m/s",
#"fitness:metrics:location:latitude": #"37.51769",
#"fitness:metrics:location:longitude": #"126.9908",
#"fitness:metrics:location:altitude": #"13.85767",
#"fitness:metrics:timestamp": #"2011-01-26T00:30"
};
FBSDKShareOpenGraphObject *course = [FBSDKShareOpenGraphObject objectWithProperties:courseDict];
// Create the action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"fitness:runs";
[action setObject:course forKey:#"course"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"course";
[FBSDKShareDialog showFromViewController:viewController
withContent:content
delegate:self];
Every time I want to share this I get the Error Code 102. I double checked the App name and everything else and I can still share any other custom OG Stories via the app, so I assume the code above is the problem.
What am I missing? Is the url property of the course required to get it working?

Celebrate a victory with Open Graph on iOS

After almost 2 days of reading through the Facebook docs, I still can't figure out why oh why my code for simply publishing a game victory does not work. If I use Facebook Sample's object, it does work (uncommented), but once I use the object, the app crashes and opens the browser (in simulator) and returns to the game again. The code is as follows:
NSDictionary *properties = #{
#"og:type": #"games.victory",
#"og:title": #"A Game Victory",
#"og:description": #"Awsum description",
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"games.celebrate";
[action setString:#"http://samples.ogp.me/500426766634310" forKey:#"victory"];
// [action setObject:object forKey:#"victory"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"victory";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
What am I doing wrong and how can I fix this, I'm quite done with the FB documentation. Also, how could I know whether the story has been posted successfully in my app? Is there some delegate callback function or anything like that?

Sharing fb image and message content within the app not working using FBSDKShareDialog

I am using the following code to share a picture and some message on the fb timeline using FBSDK open graph object and FBSDK open graph content.however the following code does nothing,no dialog is presented nor does it post anything to the timeline.am i missing anything in this code or does this code not work in the simulator?
- (IBAction)shareButtonPressed:(id)sender {
NSString *contentDesc=#"abcdcccdcc";
NSString *title=[NSString stringWithFormat:#"%# \n asd %#, asd %#",self.nameLabel.text,_fromDate.text,_toDate.text];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = _profilePic.image;
photo.userGenerated = YES;
// Create an object
NSDictionary *properties = #{
#"og:type": #"memories.memory",
#"og:title":title ,
#"og:description":contentDesc
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"memories.view";
[action setObject:object forKey:#"memories.memory"];
// Add the photo to the action
[action setPhoto:photo forKey:#"image"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"memories.memory";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
}
in the delegate method
-(void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(#"%#",error);
}
the error log is printed as follows
Error Domain=com.facebook.sdk.share Code=2 "The operation couldn’t be completed. (com.facebook.sdk.share error 2.)" UserInfo=0x7faec97bb660 {com.facebook.sdk:FBSDKErrorArgumentValueKey=<FBSDKShareOpenGraphContent: 0x7faecbc16740>, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Feed share dialogs support FBSDKShareLinkContent., com.facebook.sdk:FBSDKErrorArgumentNameKey=shareContent}
change [action setPhoto:photo forKey:#"image"]; to [object setPhoto:photo forKey:#"og:image"];
2: fatuhoku - thank for your comment. You are right - i'm using FBSDKShareAPI. If i create photo with userGenerated set to YES it is attached like photo. The photo is placed in my album (which is automatically created) with the name of my app and the post type is 'photo'. If i use userGenerated set to NO the photo is placed in internal FB stage, the post is type 'link' but i can extract photo from the post property 'picture' and with some trick by changing two parameters in picture URL w=130 and h=130 get necessary size of my photo. All this i do with API not with Dialogs.

Resources