获取游戏请求ID / 获取Facebook游戏请求通知内容
Get game request ID / Access Facebook game request notification content
我正在尝试在我的应用程序中向 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 文档说:
“为了读取收件人的所有请求,您可以使用收件人的用户访问令牌查询如下所示的图表。这将 return 应用程序中该用户的请求 ID 列表.
获取 https://graph.facebook.com/me/apprequests?access_token=[USER 访问令牌]"
但这就是我一开始所做的...
我找到了。请求应该是“/me/apprequests”
所以:
FBSDKGraphRequest(graphPath: "/me/apprequests", parameters: nil).start(completionHandler: { (connection, user, requestError) -> Void in
})
我正在尝试在我的应用程序中向 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 文档说:
“为了读取收件人的所有请求,您可以使用收件人的用户访问令牌查询如下所示的图表。这将 return 应用程序中该用户的请求 ID 列表.
获取 https://graph.facebook.com/me/apprequests?access_token=[USER 访问令牌]"
但这就是我一开始所做的...
我找到了。请求应该是“/me/apprequests”
所以:
FBSDKGraphRequest(graphPath: "/me/apprequests", parameters: nil).start(completionHandler: { (connection, user, requestError) -> Void in
})