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?
Related
I am using Facebook SDK 4.13 for iOS.
I'm successfully share custom OpenGraph story through [FBSDKShareAPI share]. The problem is - no dialog.
When I'm trying to share the same context through FBSDKShareDialog - dialog appears empty and shared post neither.
Is there a possibilities to share OpenGraph stories through dialog?
I've managed "tune" settings for my OGOStory(OpenGraphObjectStory), so it'll show correctly in fine dialog.
It's a bit confusing that in my app I have models named story and OGOS but, i hope, youl'll manage to understand.
- (void)performShareFacebookWithStory:(STLStory *)story andText:(NSString *)text
{
NSURL *imageURL = [NSURL URLWithString:[story largeImageURL]];
FBSDKSharePhoto *photo = [FBSDKSharePhoto photoWithImageURL:imageURL userGenerated:NO];
NSDictionary *properties = #{
#"og:type": #"stories_california:story", //OpenGraphObjectStory,
#"og:title": [story title],
#"og:description": [story aboutText],
#"og:url": [self storyUrlForStory:story], // it's NSString
#"og:image": #[photo],
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"stories_california:story_listen";
[action setObject:object forKey:#"story"];
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"story"; //OpenGraphPreviewPropertyName
[FBSDKShareDialog showFromViewController:_parentVC
withContent:content
delegate:self];
}
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.
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
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?
I am trying to post story via my app using Graph API of facebook SDK.
I have configured actions and object and story on its App console, and have implemented following code to achieve the same.
NSURL *imageURL = [NSURL URLWithString:#"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"];
FBSDKSharePhoto *photo = [FBSDKSharePhoto photoWithImageURL:imageURL userGenerated:NO];
NSDictionary *properties = #{
#"og:type": #"abc-holdings:glc",
#"og:title": #"Sample GLC",
#"og:description": #"Test Geo",
#"og:url": #"http://samples.ogp.me/147425295593678",
#"og:image": #[photo],
#"abc-holdings:location:longitude":#(-58.381667),
#"abc-holdings:location:latitude":#(23.381667)
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:#"abc-holdings:has_a_glc" object:object key:#"glc"];
[action setString:#"true" forKey:#"fb:explicitly_shared"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"glc";
// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;
[shareAPI share];
But this issue is that it respond me as below
Error Domain=com.facebook.sdk.share Code=201 "The operation couldn’t be completed. (com.facebook.sdk.share error 201.)" UserInfo=0x7fb9e1749190 {com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Error sharing Open Graph content, NSUnderlyingError=0x7fb9e14c5210 "The operation couldn’t be completed. (com.facebook.sdk.core error 8.)"}
Is there any idea to anyone regarding this ?
You should go to your app at Facebook. Choose Open Graph settings, choose your action type, scroll down till the end. There you will see some checkboxes Your action capabilities
Check last checkbox and try to share your content again.