Facebook UI, how to check if a user can send facebook message to another user - facebook

I want to follow up this question. I use FB.ui to send link and got exactly the same error for some users. Is there anyway to check it and decide whether to display the ui to the user ?
API Error Code: 100
API Error Description: Invalid parameter
Error Message: Viewer cannot message specified recipients.
<a href='#' onClick="
FB.ui({
method: 'send',
link: 'http://www.xxxxxxxxxxx.com',
to: ###########,
});
">Send a message</a>
Even when I use the url send method, some user does not work. For example:
Error User : https://www.facebook.com/dialog/send?app_id=123050457758183&name=People%20Argue%20Just%20to%20Win&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/&to=100000104626944
Normal User: https://www.facebook.com/dialog/send?app_id=123050457758183&name=People%20Argue%20Just%20to%20Win&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/&to=1311251197
(this is the share link example taken from https://developers.facebook.com/docs/reference/dialogs/send/)
bug reported to facebook: https://developers.facebook.com/bugs/538638372825668

Edit: in fact, everyone should be reachable through messages now. It's only there are new "filtering preferences". I guess this can_message field is now useless because it should always return true. I think it is going to be deprecated in a while.
In the user FQL table, you have a field that must verify what you need:
can_message (boolean): whether the user can send a message to another user
Source: https://developers.facebook.com/docs/reference/fql/user
select can_message from user where uid=USER_ID
USER_ID being the person that your app user want to send a message to.

You can use the FB api;
I use something like:
FB.api('/me/permissions', function (response)
{
//check contents of response for required permissions here
fb_publish_perm = response.data[0]['publish_stream'] ? response.data[0]['publish_stream'] : false;
if (fb_publish_perm)
{
// it permissions exist
}
else
{
// permissions dont exist launch the ui to request.
}
});
Please treat the above as psedo code, as it came straight off the top of my head!

Related

Facebook Graph /me missing email

We have issues with our web app and Facebook.
I'm doing the Login with scope email
FB.login(function(response) {
// my code
}, {scope: 'email', auth_type: 'rerequest', return_scopes: true});
I got the popup asking permission for the email, and other fields
I accept it, but then after getting the access_token, I call
https://graph.facebook.com/v15.0/me?fields=id,first_name,last_name,name,email,picture.type(large)&access_token={MY_TOKEN}
The email field is not in the response
What I don't understand is that user is a test user created on Facebook app page. One in Two users I create have this issue. For some other users, I have the email with the same exact procedure
Do you know what could happen?
We are experiencing the same issue.
WizKid is right. Try using https://developers.facebook.com/tools/explorer/ and you'll see that when you get no email, this tool shows "The email field was not returned. This may be because the email was missing, invalid or hasn't been confirmed." message.

The graph api /me/apprequests return http error

I use
FB.api('/me/apprequests/?access_token=' + access_token + '&date_format=' + escape('Y/m/d H:i:s eO'), function(response) {
if(response.error)
{
to get user's app requests.
but some times,some users cannot get the app requests list.
only get
{"error":{"type":"http","message":"unknown error"}}
some users may get this error all the time.
I trace this error to my GA quality,Statistical results show some users get this error As many as tens of thousands of times.
the access_token is the current user's.
why some user get unknown error with type http?
I do not get this.
thank you.
thanks for your answer.
I think this error is not caused due to the permission.because I log the access_token when one error occurs.and use facebook debug tool check it.It shows
Issued:
1362702044 (about an hour ago)
Expires:
1367886044 (in about 2 months)
Valid: True
Origin: Web
Scopes: email publish_actions user_games_activity
.So ,I do not known why those problem occur.
I have the same problem and it is resolved now.
The error message : {"error":{"type":"http","message":"unknown error"}}
means FB API's response is broken because of some other action in the page.
In my scenario, I put a html tag :button in a form, and this button is to invoke FB.api. However, when a user clicks the button, the form will be submitted automatically and does not wait the response of FB.api.
The code is as below:
<form>
<button onclick="test();">Test</button>
</form>
function test(){
FB.api('/me', function(response) {
alert(response.name);
});
}
I add "return false;" in button's onclick method after it calls test() to avoid the form automatically submitting.
I suggest you to check the javascript in the page to confirm there is no action occurs during interactive function with FB.

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.

Error using news.reads Open Graph action

I'm trying out the new Open Graph actions to build functionality like the Washington Post Social Reader. I created OG pages of type "article" and posted "news.reads" action to them. I verified that the pages are valid OG objects using the OG debugger. And the user granted the publish_actions permissions.
I publish an action with an HTTP POST to:
https://graph.facebook.com/me/news.reads?article=((article link))&access_token=...
I get this error back from Facebook:
type = u'OAuthException', message = u'An unknown error has occurred.'
So I try the same action again, and this time I get this other error:
type = 'OAuthException'
message = '(#3501) User is already associated to a article object on a unique
action type Read. Original Action ID: ((action id))'
Where ((action id)) is a valid action ID, which I can verify by viewing:
http://graph.facebook.com/((action id))
Which gives me details about the action. I tried the above several times with different pages and different users, and it's the same flow: unknown error, duplicate action error. It looks like the action is being created, however:
I don't see it on the user timeline.
And I don't see it in the Activity Log.
What am I missing?
Note If I do the above using my own app-specific nouns and verbs, everything works as expected. But I'm interested in using the built-in nouns and verbs for better aggregation on users timelines.
If you action has not been approved by Facebook, it won't show up to end-users. Only those listed in the 'Roles' section of the Application Settings will be able to publish and see the actions in the Activity log (e.g. administrators, developers and testers).
Try testing the action with a Test User. Create a new test user from the 'Roles' page and login with them. See if the action is published and appears correctly on the Activity log.
Here's what I'm using to post video watches, you can try to do the same:
function postWatch()
{
FB.api('/me/video.watches' +
'?video=<?php echo $url; ?>','post',
function(response) {
if (!response || response.error) {
alert(response.error);
} else {
//alert('Post was successful! Action ID: ' + response.id);
}
});
}
The built in Read action is defined as "unique" while your action type is not (see 'advanced' section in the action edit screen). You you can't submit Read with the same object url twice.

posting reply to inbox message?

I'm trying to post a reply to an inbox message by sending a POST request to /message_id/comments. Is this the correct way to send a reply to an inbox message ?
I'm getting the following error:
"error": {
"type": "OAuthException",
"message": "(#3) App must be on whitelist"
}
The token has every possible permission.
Do I have to ask that my app is added on a whitelist ? how to do so ?
I'm doing this in javascript+jQuery:
var params = {
access_token: token
, method: 'post'
, message: 'hi'
};
$.getJSON('https://graph.facebook.com/$message_id/comments?callback=?', params, function(json) {
});
Facebook apps by default aren't allowed to send messages on behalf of users. There is no permission you are missing. This is an extra level to prevent spam (beyond prompting the user who). You will have to contact Facebook to get your application whitelisted. I would try their developer group.
opened a support ticket right here:
http://developers.facebook.com/bugs/183144141763793?browse=search_4e8b140cbf26e6040457329
Tried all I can think of and googled for, still getting this issue
Like others have pointed out, there isn't a way to do this programmatically unless you are on Facebook's whitelist. However, I did find a way around this for my app. What I do is use Oauth to display messages from a user's FB inbox like normal. When the user clicks 'Reply' on a message, I just send them to the reply page on Facebook Mobile, like this:
$('.reply').click(function() {
var popup_window = window.open('http://touch.facebook.com/messages/compose?ids='+message_id, '_blank');
popup_window.focus();
});
Where message id is the Facebook id for the message they are replying to. In my case, I use PHP to echo the message id into a javascript variable or data-attribute when the page loads. Since the Facebook mobile page opens in a new tab, they don't even really leave my app. Since Facebook mobile has a very streamlined interface it isn't too distracting. It's not perfect, but it works and it's easier than trying to get whitelisted.