开放图谱 Facebook SDK 2.5

Open Graph Facebbok SDK2.5

我对请求和发送对象的所有开放图机制有点困惑。 目前我正在做以下事情:

FBSDKGameRequestContent *gameRequestContent = [[FBSDKGameRequestContent alloc] init];
gameRequestContent.message = [SPBLabelUtils stringMessageForKey:@"FacebookAskLivesMessage"];
gameRequestContent.recipients = friends;
gameRequestContent.objectID = @"794790780644074";
gameRequestContent.actionType = FBSDKGameRequestActionTypeAskFor;

FBSDKGameRequestDialog *dialog = [[FBSDKGameRequestDialog alloc] init];
dialog.frictionlessRequestsEnabled = TRUE;
dialog.content = gameRequestContent;
dialog.delegate = self;
NSError *error;
if([dialog canShow] && [dialog validateWithError:&error]){
    [dialog show];
}else if(error){
    [self showAlertForError:error];
}
else{
    [self showAlertWithMessage:[SPBErrors messageForCode:@"FBE:CantShowDialog"] title:[SPBLabelUtils stringMessageForKey:@"FacebookTitle"]];
}

并在我的中出现以下错误:

- (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didFailWithError:(NSError *)error

Error Domain=com.facebook.sdk.share Code=2 "The operation couldn’t be completed. (com.facebook.sdk.share error 2.)" UserInfo=0x17887f7c0 {com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Sorry, this feature isn't available right now: An error occurred while processing this request. Please try again later.}

我不确定我是否完全理解 objectID 的想法 - 我是否需要在每次需要请求时都创建一个对象? 如果我这样做,我是否需要将 'create code' 和 link 用于包含所有元数据的页面? 为什么我每次都要创建一个新对象?我什至不需要阅读它,只是为了通知其他玩家他们有一个待处理的对象请求。

API 不是 100% 清楚的。 如果有人可以 explain\give 教程 link\post 示例代码,那就太好了。 谢谢

您从哪里获得对象的 ID?您正在使用的是一个示例对象。您将需要创建(至少)一个真正的 Open Graph 对象,您可以在代码中使用它来引用。

我已经坚持了几个小时了。希望有人能在我的回答中找到解决这个问题的方法。

在您的项目设置中,转到 Facebook 上的 "Open Graph" 部分。创建一些对象类型。然后上面有个按钮"Tools & support"。

点击后你会看到几个链接,你需要的是"Object browser"。

对象浏览器是必填部分。在带有 "Type:" 文本的组合框中,它包含我们之前创建的对象类型。所选类型有一个按钮 "New object"。

当您创建新对象时,它会获得他的 ID。 这就是您要查找的对象 ID。

可能有更好的方法找到 "Object Browser".

部分

还有一件重要的事情:

FBSDKGameRequestContent *Content = [[ FBSDKGameRequestContent alloc ] init];
            Content.title = @"Title test";
            Content.message = @"Test message";
            Content.data = @"Test data";
            Content.objectID = @"1012001268809871";
            Content.actionType = FBSDKGameRequestActionTypeAskFor;
            Content.filters = FBSDKGameRequestFilterAppUsers;
            fbRequestDialog.content = Content;
            fbRequestDialog.delegate = self;
            BOOL Result = [ fbRequestDialog show ];

这段代码对我来说很好用。因此,正如您所见,"objectID" 字段是字符串,但它代表数字字符串。现在你知道它是什么样子了吧。