toiavalle toiavalle - 1 month ago 15
iOS Question

Get game request ID / Access Facebook game request notification content

I am trying to send requests with data to Facebook friends in my app. The requests are successfully sent and I do get notifications. However the message on the notifications is not what I specify (the notification I get is xxxxx sent you a request. I specified Please help me with 5 lives). Also, I can't access any data of the request received.

This is how I'm sending the request:

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)
}


This is how I'm trying to get it in the other end:

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(user) prints:

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;
};


Update: I found out that if I copy the request ID and copy it for graph path it works. Does anyone knows how to get this ID from receivers end

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


and pasted...

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


now print user prints:

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";


})

The problem is I copied when I log in with the user sending and copied to the user receiving. I still can't just access it just by code from the receiver.

Facebook documentation on Game request says:

"In order to read all the requests for a recipient for you can query the graph as shown below using the recipient's USER ACCESS TOKEN. This will return a list of request ids for that user in the app.

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

But thats what I was doing at first...

Answer

I found it. the request should be "/me/apprequests"

so:

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