Requests 2.0, empty data in graph after successfully sending requests - facebook

I'm seeing some strange behaviour with Requests.
I initiate a requests dialog with:
method: 'apprequests'
to: 'someUid'
(and some data for message, title, data)
The user approves the Request, and I get back a valid response, giving me the request Id, the user Ids it was sent to, and the updatedFrictionless flag. However, when reading the request from the graph later with either:
https://graph.facebook.com/?ids=REQUESTID_USERID&access_token=RECEIVINGUSERTOKEN
or
https://graph.facebook.com/REQUESTID_USERID?access_token=RECEIVINGUSERTOKEN
I get back no data !
The first graph call will give me an empty array (an un-named array not 'data', just simply [ ] )
The second, gives me 'false'
REQUESTID is the request Id I get back from the original call, USERID is the receiving USERID.
The receiving user is me, and I do see the request in my notifications, but using the graph explorer to check my 'apprequests', its empty.
Any ideas? I have Requests 2.0 enabled, and call FB.init with frictionlessRequests: true..

Does it work with your app access token?

Related

400 Bad Request when implementing custom friend selector

I'm trying to implement a custom multiple friend selector to invite users to my game. I get the list of users calling the Graph API call InvitableFriends, and create a UI for it.
After the user selects the corresponding users, I get all the invitation tokens of the users, and make a call to an App Request as follows:
public void InviteFriends(string message, string title, FacebookDelegate callback, string[] to = null, string data = "")
{
if (FB.IsLoggedIn)
{
FB.AppRequest (message,
to,
"",
null,
null,
data,
title,
callback);
}
}
But when the call is made, I'm getting the following error:
400 Bad Request
UnityEngine.Debug:LogError(Object)
FbDebug:Error(String)
Facebook.FallbackData:JSFallback(String)
Facebook.AsyncRequestDialogPost:CallbackWithErrorHandling(FBResult)
Facebook.<Start>c__Iterator0:MoveNext()
My callback function is never called, so I can't see what the error is.
I'm using Unity 4.3 & Facebook SDK 5.1
Thanks for your help!
EDIT: I'm pretty confident that the issue is that in the TO parameter I'm passing the invite tokens that the Invitable Graph call is giving me, AND NOT THE Ids.
I tested the InteractiveConsole.cs example of friendsmash with the invitable token and it also failed. How can I get the ids of the invitable friends?
just check the url request. It may be some thing wrong with it.
or
go to https://developers.facebook.com/apps/{app-id}/app-details/
in "app Info" section, choose the proper category and sub category.
I had a similar issue.. Figured out that FB.init() has to be called before using the invitable api. Without it you would get a "400 Bad Request"
I was keeping the old access token in playerprefs and just checking it again for validity and not actually initialising FB to save load time. But eventually I had to do FB.init()

How get the notification ID when user enter in you app

I'm using the Facebook requestdialog to show my friend list and invite,this in a Facebook Web APP, using this:
function sendRequestViaMultiFriendSelector() {
FB.ui(
{
method: 'apprequests',
message: 'Selección de amigos a los que invitar a KugaBar'
}, requestCallback);
}
function requestCallback(data) {
console.log(data);
}
It works (ok).
But I need to identify the user when enter in my APP, you see the requestCallback data and see a "request", but when the users click on the notification and enter in the APP
I don't know how identify the request to detect if the user is accessing by the notification.
EDIT: OK I found it.
The param in the GET vars are "request_ids", but one problem appear, this param only come if the user previously have accepted the permissions, if the user clicks on the notification, and accept the permissions, hitting enter: this param doesn't exist, if the user enter again (not need to accept nothing) this param exists in the URL.
Are there any method to get this param in the first time the user enter?
Thanks
When the user first clicks on a request, you should get the request_id from the URL and store it in a cookie. When the user has completed logging in, check if the cookie exists and then update your record accordingly.
Notifications and Requests are NOT the same thing on Facebook. In your case you're talking about Requests. Request ids are passed to the app as a GET parameter 'request_ids' which is a comma separated list.
To be able to access this parameter after login dialog, you want to save your GET parameters from the original launch URL before redirecting to the OAuth dialog and pass them around in the redirect URL. This way you solved this problem for all of your future GET parameters.
If you're using PHP, the function you're looking for is http_build_query. I'd highly discourage from using a cookie to store one-time and easily accessible URL parameters.

deleting facebook requests

The facebook docs here say "it is the Developers' responsibility to delete a Request once it has been accepted". As far as I understand, when someone sends a request to multiple users on facebook like this:
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'test message'
}, requestCallback);
}
only one request_id is returned via requestCallback() function.
Then, if I delete the request when someone accepts it, how would other users accept the deleted request?
when user comes following the app request, you can get request id's using
$_GET['request_ids']
then retrieve all the request ids with which you can call graph api to delete the corresponding requests like below:
if(isset($_GET['request_ids']))
{
$request_ids = $_GET['request_ids'];
}
$request_ids = explode(",", $request_ids);
foreach($request_ids as $request_id)
{
$full_request_id = $request_id."_".$fbid; //$fbid is current user facebook id
$facebook->api("$full_request_id","DELETE");
}
Check out the Request ID Format section of the FB request overview page.
The actual graph path for a request actually sent to specific user is "request-id"_"recipient-user-id".
you can access to facebook on mobile mode (m.faceook.com)
1-access the invitation panel
2-display all the invitations
3-open console mode in chrome
4-activate jquery by cpying and pasting all the jquery.min code into console
and excecute this script :
$("._54k8._56bs._56bt").trigger("click");
that will cancel or the invitation sent

Facebook JS SDK throwing 104 error when attempting to delete a app request

I have setup the facebook javascript sdk to initialize a friend invite dialog to send requests to friends. Clicking on the invite in Facebook, brings the user back to the site.
The query string has any and all request_ids that have not been handled (deleted).
I am following the documenation listed at the FB developers site here which states:
JavaScript SDK:
FB.api(requestId, 'delete', function(response) {
When they are returned to my site, the querystring has a request_ids parameter:
example: www.mysite.com/somepage?request_ids=0493834050
my Javascript code looks like this:
FB.api(requestIds[i], 'delete', function (response) {
console.log(response);
});
But the error I get is:
ERROR
code: 104
message: "An access token is required to request this resource."
type: "OAuthException"
All I want to do is delete the request ID. before I was even running the above code, the querystring was building up with every submitted request. It does appear they have been removed, because the querystring is reduced down to a single request id. But I am still uncertain it has been handled properly.
NOTE I am not using the Graph version - as I have not setup Graph on the app settings in Facebook.
I have the Facebook C# sdk - if someone has an easy way to do this here. I have tried the following with the same results.
var fbClient = new FacebookClient(accessToken)
fbClient.Delete(requestId);
I don’t see what’s possibly unclear about the error message – you need a valid access token to be able to delete requests, but by the looks of it you don’t have one.
So you’ll either have to have the user connect to your app in order to get an active access token for him; or you have to do it using your own app access token (but that’d have to be done server-side then, because you don’t want to transfer your app access token to the client side).

Giving a redirect url parameter when sending an app generated request to a facebook user

I am sending an app generated request to a user(already authorized the app) by calling the below js function
function send_app_request(){
FB.api( "/" + '<TO-USER-ID>' + "/apprequests", "POST", {
message: "Custom Request for you!",
title: "Sample title",
access_token: "<MY-APP-ACCESS-TOKEN>"
}, function(response) {
alert(response.toSource());
console.log(response);
});
}
The script is working fine, and when the user clicks on the the app icon(with the red notification), at the top right corner of the canvas, he gets redirected to ther app's index page(apps.facebook.com/MY-APP), which is also fine. My question is, what parameter should I add in my FB.api call so that the user gets redirected to my desired app url(eg: apps.facebook.com/MY-APP/show-article/?article_id=5) instead of the index url.
Requests always direct user to your application canvas.
Citing Requests documentation:
Requests are only available for Canvas apps, not websites, as accepting a request will direct the user to the Canvas Page URL of the app that sent the Request.
Possible solution will be addition of desired URL within Request data property and once user land on your Canvas URL with requests_ids passed in URL arguments, read those requests and decide based on data property where user should be redirected.
data
Optional, additional data you may pass for tracking. This will be stored as part of the request objects created. The maximum length is 255 characters.
Update:
To get the data assigned with application/user request fetch it from Graph API:
https://graph.facebook.com/<REQUEST_OBJECT_ID>_<USER_ID>?access_token=APP_ACCESS_TOKEN