In my website, users can post to their FB wall from my website. I,am using graph api for that. My api code is,
FB.api(
"/me/photos",
"POST",
{
"caption": "My caption",
"url": "My image url"
},
function (response) { console.log(response);
if (response && !response.error) {
$('#post_response').html('See feed');
}
}
);
During this api call getting an error,
code: 200
message: "(#200) Requires extended permission: publish_actions"
type: "OAuthException"
My Fb login Api is,
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
document.getElementById('loginBtn').style.display = 'none';
getUserData();
}
},
{
scope: 'email,public_profile,publish_actions,manage_pages',
auth_type: 'rerequest',
return_scopes: true
}
);
I also tried,
1)
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
document.getElementById('loginBtn').style.display = 'none';
getUserData();
}
},
{
scope: 'publish_actions'
}
);
2)
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
document.getElementById('loginBtn').style.display = 'none';
getUserData();
}
},
{
scope: 'publish_actions',
auth_type: 'rerequest'
}
);
By calling api,
FB.api("/me/permissions", function (response) {
console.log(response);
});
I understood that, only getting 'email,public_profile' permissions.
How to get 'publish_actions' permission??
Is there any other methods to do this?? I want to post image post to users wall and users page...
Please help me to fix this issue...
Thanks in advance.
Make sure that you have added the FB account to test user under FB app settings >test user . Because In order to use permissions like publish _action your app needs to be approved by Facebook,but with test users you can test the functionalities.
Related
I want to utilize Facebook Messenger login connect flow in my web application - https://developers.facebook.com/docs/facebook-login/login-connect/
For that, I've created a test app and set up an initial page in the "messenger" section.
And I have, basically, this code (shown partially):
<script async='' defer='' crossorigin='anonymous' src='https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v10.0&appId=<skipped>&autoLogAppEvents=1' nonce='<skipped>' />
and
window.fbAsyncInit = function() {
window.FB.init({
appId: "<skipped>",
autoLogAppEvents: true,
xfbml: true,
version: "v10.0"
});
window.FB.getLoginStatus(function(response) {
// Called after the JS SDK has been initialized.
console.log("Inside window.FB.getLoginStatus");
statusChangeCallback(response); // Returns the login status.
});
};
function loginUsingJSSDKLoginDialog() {
console.log("Inside loginUsingJSSDKLoginDialog");
window.FB.login(
function(response) {
if (response.status === "connected") {
window.FB.api("/me", function(response) {
console.log("Successful login for: " + response.name);
var element = document.getElementById("status");
document.getElementById("status").innerHTML =
"Thanks for logging in, " + response.name + "!";
});
} else {
document.getElementById("status").innerHTML = "You are not logged in!";
}
},
{
scope: "public_profile,email,user_messenger_contact",
messenger_page_id: "<skipped>",
reset_messenger_state: true
}
);
}
An issue is that the login dialog that'll pop up won't be the one of Messenger but the standard Facebook login one.
Why is that? How to fix it?
What I need is, as mentioned, "Facebook Messenger login connect flow"
In about 0.3% of users, I can't get their FB ID with JS API. On some occasions I have gotten it before for those users. What could be the cause of this and any ideas on how to fix it?
As far as I know most of those users were on Windows and using firefox.
My code:
window.fbAsyncInit = function () {
FB.init({
appId : "xxxx",
status : true,
cookie : true,
xfbml : true,
oauth : true
});
FB.Canvas.setSize({width:$("#mainbody").outerWidth(),height:$("#mainbody").outerHeight()});
FB.getLoginStatus(function (response) {
if(response.authResponse){
if(response.authResponse.userID){
fbId = response.authResponse.userID;
$("#hiddenFbId").val(fbId);
setSession();
}
}
if (response.status === 'connected') {
FB.api(
"/me?locale=et_EE",
function (response) {
if (response && !response.error) {
fbName = response['name'];
fbId = response['id'];
$("#hiddenFbId").val(fbId);
fbEmail = response['email'];
setSession();
}
});
} else {
FB.login(function (response) {
if (response.authResponse) {
if(response.authResponse.userID){
fbId = response.authResponse.userID;
$("#hiddenFbId").val(fbId);
setSession();
}
FB.api(
"/me?locale=et_EE",
function (response) {
if (response && !response.error) {
fbName = response['name'];
fbId = response['id'];
$("#hiddenFbId").val(fbId);
fbEmail = response['email'];
setSession();
}
});
} else {
fbDenied = true;
}
}, {
scope : 'public_profile,email,user_likes'
});
}
});
}
Never call FB.login in the asynchronous (!) callback function of FB.getLoginStatus. Some browsers block the login popup if you do that, you always need to call FB.login on user interaction - and calling it on page load is a bad idea anyway. Don´t force the user to authorize your App right when they enter your App and before they know what your App is about.
FB.getLoginStatus on page load to refresh the User Token and to check if the user is authorized
FB.login on mouse click
It is also easier that way to remove some redundant code and move your FB.api call to a function.
It may or may not solve your problem, but it´s definitely important and a commong source of errors.
This question already has an answer here:
(#200) The user hasn't authorized the application to perform this action
(1 answer)
Closed 8 years ago.
got error when i want to post text in facebook wall .
this is my code
function logout() {
FB.logout(function(response) {
alert('logged out');
});
}
// i am able to login successful . using this method .
function login() {
FB.login(function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
alert('Access Token = ' + access_token);
alert("Welcome! Fetching your information.... ");
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
alert("User cancelled login or did not fully authorize.");
console.log('User cancelled login or did not fully authorize.');
}
},{
scope: 'publish_actions',
return_scopes: true
});
}
// here i call this method to post the text in FB wall . and i am getting status logged in a but i got error .
function SubmitPost() {
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
alert('logged in');
try {
var wallPost = {
message: "post in fb" ,
picture: '',
link: '',
name: 'test app posted in your wall',
caption: '',
description: ('Test description')
};
FB.api('/me/feed', 'post', wallPost, function (response) {
if (!response || response.error) {
/*action*/
alert('Message could not be Posted.');
alert(response.error.message);
console.log(response.error.message);
} else {
/*action*/
alert('Message Posted successfully.');
}
});
}
catch (err) { alert('SubmitPost: ' + err);
}
} else {
alert('not logged in');
}
});
}
Please check your host URL matches with the URL given in the Facebook app "Website URL". Both should be exactly same.
If your are not added in facebook Website URL which reside under your App setting , then you can create this by hitting to "Add Platform" .
Steps to get website URL for the Facebook application:
1] If you are not created facebook app , To create Goto
https://developers.facebook.com/?ref=pf
2] Select Apps -> Create a new app
3] Fill the app details in the popup. Click on Create App
4] You will be redirected to dashboard page of your newly created application.
[ Note down the AppID]
5] Then click on "Settings" present at left side and then click on Add Platform
6] Choose "Website" from the popup menu.
7] Now you can find 2 fields : Site URL and Mobile Site URL.
Here you should fill your website URL where your are calling facebook SDK.
I want publish a post on my friend's wall via Facebook Api in Javascript, but this code don't run correctly when I insert in "FB.api" the "privacy". Can someone help me?
Thank you.
var privacy = {value: 'CUSTOM', friends: 'SOME_FRIENDS', allow: '{UID}'};
var privacy2 = JSON.stringify(privacy);
FB.api("/{UID}/feed", 'post', {
message: 'Message',
privacy: privacy2,
}, function(response) {
if (!response || response.error) {
alert(response.error);
} else {
alert('Message sent!');
}
}
);
Change the privacy JSON to include quotes around your keys as well:
var privacy={"value":"CUSTOM", "friends": "SOME_FRIENDS", "allow":"{UID}"};
FB.api("/{UID}/feed", 'post', {
message: 'Message',
privacy: privacy,
}, function(response) {
if (!response || response.error) {
alert(response.error);
} else {
alert('Message sent!');
}
}
);
However, it appears that you cannot post private messages to another user's wall. From the privacy settings page on Facebook:
Note: The privacy parameter only applies for posts to the user's own
timeline and is ultimately governed by the privacy ceiling a user has
configured for an app. It does not apply to posts made by an app on
behalf of a user to another user's timelines or to Pages, events, or
groups. In those cases, such posts are viewable by anyone who can see
the timeline or content in the group or event.
This appears to be why you are getting an OAuth error.
I use Facebook login using FB.login (and I don't want to use the Facebook login button). My problem is that after login, the Facebook dialog don't show the listed permission, as follows.
FB.login(function (response) {
if (response.status == "connected") {
//alert(" connected ");
}
else {
//alert(" not connected ");
}
}, { scope: 'email' });
The Facebook dialog show "Access my basic information" only. How do I fix this problem?
Note: if I try the Facebook login, it shows the permission correctly.
Note 2: the response after the user clicks Allow is:
User cancelled login or did not fully authorize.
That's because of a mistake in the official documentation.
The property name for the permissions is not "scope", but "perms":
FB.login(function (response) {
if (response.status == "connected") {
//alert(" connected ");
}
else {
//alert(" not connected ");
}
}, { perms: 'email' });