获取游戏请求ID /访问Facebook游戏请求通知内容

时间:2016-10-23 20:41:40

标签: ios facebook request swift3 facebook-ios-sdk

我正在尝试将数据请求发送到我的应用中的Facebook好友。请求已成功发送,我收到通知。然而,通知上的消息不是我指定的(我得到的通知是xxxxx向您发送请求。我指定请帮助我5个生命)。此外,我无法访问收到的请求的任何数据。

这就是我发送请求的方式:

    func sendLifeRequest(index: Int) {
        let content = FBSDKGameRequestContent()
        content.message = "Please help me with 5 lives"
        content.data = "5lives"
        let id = facebookFriends[index].id as NSString
        var to: [NSString] = [NSString]()
        to.append(id)
        content.recipients = to
        FBSDKGameRequestDialog.show(with: content, delegate: self)
    }

这就是我试图在另一端获得它的方式:

     FBSDKGraphRequest(graphPath: "https://graph.facebook.com/me/apprequests?access_token=" + FBSDKAccessToken.current().tokenString, parameters: nil).start(completionHandler: { (connection, user, requestError) -> Void in
        print(requestError) // prints nil
        print(user)
    })

print(用户)打印:

Optional({
id = "https://graph.facebook.com/me/apprequests";
"og_object" =     {
    id = xxxxxxxxxxxxx;
    type = website;
    "updated_time" = "2016-10-19T05:32:20+0000";
};
share =     {
    "comment_count" = 0;
    "share_count" = 0;
};

更新:我发现如果我复制请求ID并将其复制为图形路径就可以了。有谁知道如何从接收器端获取此ID

func gameRequestDialog(_ gameRequestDialog: FBSDKGameRequestDialog!, didCompleteWithResults results: [AnyHashable : Any]!) {
    print("request sent")
    print(results) // copied ID from here
}

并粘贴......

FBSDKGraphRequest(graphPath: THE ID HERE, parameters: nil).start(completionHandler: { (connection, user, requestError) -> Void in
    print(requestError) // prints nil
    print(user)
})

现在打印用户打印:

Optional({
application =     {
    category = Games;
    id = xxxxxxxxxxxx;
    link = "https://www.facebook.com/games/?app_id=1841299476156545";
    name = "Crazy Traffic Saga";
};
"created_time" = "2016-10-24T21:25:34+0000";
data = 5lives;
from =     {
    id = xxxxxxxxxxxx;
    name = "xxxxxxxxxxxxxx";
};
id = xxxxxxxxxxxx;
message = "Please help me with 5 lives";

})

问题是我在用户发送并复制到用户接收时登录时复制了。我仍然不能只通过接收器的代码访问它。

关于游戏请求的Facebook文档说:

“为了阅读收件人的所有请求,您可以使用收件人的USER ACCESS TOKEN查询如下图所示的图表。这将在应用程序中返回该用户的请求ID列表。

GET https://graph.facebook.com/me/apprequests?access_token=[USER ACCESS TOKEN“”

但那就是我最初做的事情......

1 个答案:

答案 0 :(得分:1)

我找到了。请求应为" / me / apprequests"

这样:

FBSDKGraphRequest(graphPath: "/me/apprequests", parameters: nil).start(completionHandler: { (connection, user, requestError) -> Void in
})