我正在尝试将我的应用程序中的照片分享到Facebook,就像Instagram一样,通过切换“在Facebook上分享”,用户可以在墙上拍摄漂亮的大照片。
我在Facebook上完全遵循了“开放图形的自定义故事”教程: https://developers.facebook.com/docs/ios/open-graph
我甚至在iOS上按照教程代码下载了Facebook的示例项目。我复制了这段代码并用我的命名空间替换了命名空间,动作和对象。这是代码:
// stage an image
[FBRequestConnection startForUploadStagingResourceWithImage:image completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(@"Successfuly staged image with staged URI: %@", [result objectForKey:@"uri"]);
// instantiate a Facebook Open Graph object
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
// specify that this Open Graph object will be posted to Facebook
object.provisionedForPost = YES;
// for og:title
object[@"title"] = @"Roasted pumpkin seeds";
// for og:type, this corresponds to the Namespace you've set for your app and the object type name
object[@"type"] = @"fbogsample:dish";
// for og:description
object[@"description"] = @"Crunchy pumpkin seeds roasted in butter and lightly salted.";
// for og:url, we cover how this is used in the "Deep Linking" section below
object[@"url"] = @"http://example.com/roasted_pumpkin_seeds";
// for og:image we assign the uri of the image that we just staged
object[@"image"] = @[@{@"url": [result objectForKey:@"uri"], @"user_generated" : @"false" }];
// Post custom object
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
// get the object ID for the Open Graph object that is now stored in the Object API
NSString *objectId = [result objectForKey:@"id"];
NSLog(@"object id: %@", objectId);
// create an Open Graph action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:@"dish"];
// create action referencing user owned object
[FBRequestConnection startForPostWithGraphPath:@"/me/fbogsample:eat" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(@"OG story posted, story id: %@", [result objectForKey:@"id"]);
[[[UIAlertView alloc] initWithTitle:@"OG story posted"
message:@"Check your Facebook profile or activity log to see the story."
delegate:self
cancelButtonTitle:@"OK!"
otherButtonTitles:nil] show];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Encountered an error posting to Open Graph: %@", error.description);
}
}];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Encountered an error posting to Open Graph: %@", error.description);
}
}];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Error staging an image: %@", error.description);
}
}];
这是日志:
问题是,即使对象显示在对象浏览器中,帖子永远不会进入我的墙,。转到developers.facebook.com上的应用仪表板并打开图表,我看到故事存在,但即使应用程序这样说,也没有共享故事。
怎么了?求救!