Notification not sending to facebook friend - javascript

I have created an application where i am trying to invite friends via facebook invite friends js method but all working fine but no notification sent to that friend.
My Application Link: http://www.huzoorbux.com/fl/app/android/www/homepage_nopost.html
My Code:
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.api(
"/me/invitable_friends",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
if(top.location != self.location) {
top.location = self.location
}
FB.init({
appId:'228877127299395',
cookie:true,
status:true,
xfbml:true
});
function FacebookInviteFriends()
{
FB.ui({
method: 'apprequests',
message: 'Join My Job Buddy'
});
}
</script>
<div class="connectbutton5" id="ol">Invite Friends</div>

App Requests are for games only, that may be the reason. And always use a callback function for error handling, maybe you are missing an error:
FB.ui({method: 'apprequests',
message: 'YOUR_MESSAGE_HERE'
}, function(response){
console.log(response);
});
Also:
The invitable_friends API is only available for games that have a Facebook Canvas app implementation using version 2.0 of the Graph API.
Source: https://developers.facebook.com/docs/games/invitable-friends/v2.1
If you want to invite someone to a website, use the Send and Share Dialogs and Buttons. You don´t even need to authorize the user for them.

Related

How can I access user likes information using Graph API?

I am trying to use facebook Graph API to fetch user details.
Below is my FB.api query :
FB.api('/me', 'GET', { access_token: token, fields:'id,name,email,gender,location,likes' }, function(response) {
console.log(response);
alert(response);
});
With above query i am able to fetch id, name and gender but not location, email and likes.
Version for FB SDK : v2.5
I think the issue is related to some permissions required to fetch such private data of user.
Please suggest what need to be done to get all the data.
You need to ask for the permissions in the login process, with the scope parameter. Here is a list of those: https://developers.facebook.com/docs/facebook-login/permissions
Here´s how to use FB.login with additional permissions:
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
document.getElementById('loginBtn').style.display = 'none';
getUserData();
}
}, {scope: 'email,user_likes,user_location'});
Source: http://www.devils-heaven.com/facebook-javascript-sdk-login/
Make sure you read about Login Review too: https://developers.facebook.com/docs/facebook-login/review

Facebook Login API data-scope permission didn't work?

My code as below, and it's will display Facebook login button, and send permission request for "public_profile, user_groups, publish_actions".
but after user logined, always only has "public_profile", other's setting are missing.
May I know, are there anything I missing?
HTML Code
<div class="fb-login-button
align-right"
data-max-rows="1"
data-size="medium"
data-show-faces="false"
onlogin="MyFBLogin()"
data-auto-logout-link="false"
data-scope="public_profile, user_groups"></div>
Javascript Code
$(function () {
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/zh_TW/all.js', function () {
FB.init({
appId: 'xxxxxxx',
xfbml: true, // parse XFBML
version: 'v2.0'
});
$('#loginbutton,#feedbutton').removeAttr('disabled');
});
});
function MyFBLogin(){
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
//Logined
}
else {
//Not logined
}
});
}
PS: the permission setting is work when I using my app develop account, but other's account didn't work.
If your app asks for more than than "public_profile", "email" and "user_friends" permissions it will require review by Facebook before your app can be used by people other than the app's developers.
While facebook accept your review submit, only de developers of the app can do all the actions on the app flow.
Documentation for review

Facebook Login via PHP SDK, then use JS SDK

I have developed an application where users login via facebook (PHP SDK); now I would like to add JS SDK too, because I want to implement a generic friend selector (http://facebook-friend-selector.codersgrave.com/) that works with JS SDK. I have two questions about:
1) Can mixing the two SDK lead to problems?
2) I added the JS SDK code as explained in the documentation and tried a simple request
FB.api('/me/friends', function(response) {
alert(JSON.stringify(response));
});
but I get an error (unknown error); I also tried a dialog box
FB.ui({
method: 'feed',
link: 'https://developers.facebook.com/docs/dialogs/',
caption: 'An example caption',
}, function(response){});
but the box appears and suddenly disappears. I think the issue is related to the authentication...I guess, since my users are authenticated via PHP, that I need to pass the access token to JS, but how? This question Passing the Facebook Authorization Token from PHP to Javascript seems to be exactly what I need but I don't understand the answer: it says to store the token in a cookie, but how can JS know about it, which name the cookie should have?
Finally, if I do something like
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
alert('connected');
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
}
});
I actually get a "connected" alert, that means that JS knows that the user is logged in, even if the login was via PHP, so where is the problem?
Solved. My code contained two stupid mistakes, this is the correct code:
function test(){
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('/me/friends', function(response) {
alert(JSON.stringify(response));
});
}
});
}
Test
In the first version the call to the friends method was outside the getLoginStatus method, so it was called before setting the variable accesToken, furthermore, I haven't the "return false" statement after the test() call.

Invite friends popup is struggling, if the user is not logged in

I have created an invite friends code, which is properly working if an FB user is logged in.
If I remember correctly, it also worked, when there were no active fb users, in this case it simply shown a fb login page and then it went to an invitation.
Currently the 'invite facebook friends' link is really struggling, if there aren't any active facebook users.
FB.ui({
appId: '"' + appId + '"',
method: 'apprequests',
display: 'iframe',
message: '"' + message + '"',
title: 'Send your friends an application request'
},
function (response) {
if (response && response.request_ids) {
FB.api(response.request_ids, 'delete');
}
});
Did I do something wrong, or is this a bug in the Facebook invitation?
It seems, I got an answer on the Facebook bug site. However, it should help anybody , who has a lack of FB api knowledge . The documentation didn't show this example:
If there aren't any active fb session , it just open a login screen.
Finally I just realised what happened:
It doesn't show a login screen , if you use an IFRAME.
Do not use that!!
Thank you for Noorin Ladhani.
<script>
document.getElementById('send-to-many').onclick = function() {
FB.ui({
method: 'apprequests',
message: 'Visit my page'
}, Log.info.bind('send-to-many callback'));
}
</script>

Problem with Facebook Open Graph API call... need an active access token?

I'm using Facebook's open graph api along with the JavaScript SDK on my site. My goal is for a user to connect to my site and then after performing certain actions on my site publish a message to the users facebook stream. I have the facebook connect function working just fine. During the connect I request email, publish_stream, offline_access permissions. I think those are all I need for what I'm trying to do. Now when the user connects via facebook connect I do get and capture the facebook access token and secret though I don't know what to do with them.
According to Facebook's shoddy documentation for the JavaScript SDK... to do what I'm trying to do it says to use the following code:
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
I'm doing just that as a test and instead of alerting the response I'm stringifying the JSON response and writing to the console. Suffice it to say the stream publish fails and the response is this:
{"error":{"type":"OAuthException","message":"An active access token must be used to query information about the current user."}}
If the user is 'connected' to my site via facebook connect and accepted all the permissions I specified, don't I have a valid access token? Is the access token another parameter I have to pass to the api call?
Make sure you have all this in the page:
<BODY>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
FB.init({
appId : APP_ID, // the app ID you get when you register your app in http://www.facebook.com/developers/
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
if (FB.getSession() != null) {
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
</script>
The above code worked for me with the publish_stream permission. Make sure that the code is not running before the javascript api has received the access token. Run:
console.log(FB.getSession())
directly above the FB.api call to make sure you have an access_token.

Categories