我想(使用Facebook的iOS sdk的很多!)。我想發佈一個關於用戶在不離開應用程序的情況下運行的故事。我正在嘗試使用構建在對象「課程」中的Facebook以及內置的運行。Facebook的開放圖:內置對象fitness.course
我發現文檔非常混亂,我的代碼變得非常混亂,我相信它是嘗試實現此解決方案的最糟糕方式。
我用下面的代碼得到的錯誤是:
2014-04-01 23:10:13.238 Fitness_App[2313:60b] Encountered an error posting to Open Graph: Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x16ba5190 {com.facebook.sdk:HTTPStatusCode=500, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 1611072;
message = "The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: course.";
type = Exception;
};
};
code = 500;
},com.facebook.sdk:ErrorSessionKey =}
我一直在努力與此,無法得到解決!
-(void) publishStory
{
// 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"] = @"running title";
// for og:type, this corresponds to the Namespace you've set for your app and the object type name
object[@"type"] = @"fitness.course";
// for og:description
object[@"description"] = @"running description";
// 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([NSString stringWithFormat:@"object id: %@", objectId]);
// Further code to post the OG story goes here
// create an Open Graph action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:@"fitness.course"];
[FBRequestConnection startForPostWithGraphPath:@"/me/fitness.runs" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog([NSString stringWithFormat:@"OG story posted, story id: %@", [result objectForKey:@"id"]]);
} else {
// An error occurred, we need to handle the error
NSLog(@"Encountered an error posting to Open Graph: %@", error.description);
}
}];
} else {
// An error occurred
NSLog(@"Error posting the Open Graph object to the Object API: %@", error);
}
}];
}
我不認爲這是正確的Facebook自己的內置對象之一?我沒有在我的名字空間中創建任何自定義對象。 – Sarah92