Post feed with js sdk to pagewall - facebook

Im trying to send posts to a wall of a page im an admin to through the js sdk. I have made it do i can do it for myself(my personal user) but i cannot get it to work as the "page".
<div id="fb-root"></div>
<script type="text/javascript">
function SendToFacebook()
{
window.fbAsyncInit = function () {
// init the FB JS SDK
FB.init({
appId: '**CORRECT ID**', // App ID from the app dashboard
channelUrl: '**MYPAGE**/channel.html', // Channel file for x-domain comms
status: false, // Check Facebook Login status
xfbml: true // Look for social plugins on the page
});
FB.ui(
{
method: 'feed',
name: 'MyFeed',
link: '',
// picture: '',
caption: 'My caption',
description: 'test',
message: 'MESSAGE?',
},
function (response) {
if (response && response.post_id) {
alert('Delat på facebook.');
} else {
alert('Inte delat på facebook.');
}
}
);
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK asynchronously
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) { return; }
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
}
</script>
This posts to my own user page, and ive tried the "to" parameter but it send the post from my personal user to the page. Is there any way to make this though the login function?
bare in mind that im fairly new to this so demos and examples are welcome.

I got it to work after a hard days work, if any1 is interested heres how i did.
<script type="text/javascript">
function SendToFacebook()
{
window.fbAsyncInit = function () {
// init the FB JS SDK
FB.init({
appId: '***', // App ID from the app dashboard
channelUrl: '***', // Channel file for x-domain comms
status: false, // Check Facebook Login status
xfbml: true // Look for social plugins on the page
});
FB.login(function (response) {
FB.api('/me/accounts', function (apiresponse) {
var data = {
message: "mymessage",
display: 'iframe',
caption: "caption",
name: "name",
description: "description",
to: **wallid**,
from: **wallid**
};
FB.api('/**wallid**/feed', 'post', data, function () {
console.log(arguments);
});
});
}, { scope: 'manage_pages' });
};
// Load the SDK asynchronously
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) { return; }
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
}
</script>

I found this solution and I tried it, although I dont know how it was 3 years ago, now you need to append page access token you receive via /me/accounts calling (also you must be admin of that page etc.) so todays working solution could look like this:
FB.api('/me/accounts', function (apiresponse) {
console.log(apiresponse);
var data = {
message: "mymessage",
//display: 'iframe',
caption: "caption",
picture: 'www.bla.com/image.jpg',
link: 'www.facebook.com',
name: "name",
description: "description",
to: **APP IP**,
from: **APP IP**,
access_token: apiresponse.data[0].access_token
};
FB.api('/**APP IP**/feed', 'post', data, function () {
console.log(arguments);
});
});

Related

Facebook SDK 2.8 doesnot give email address

I am trying to implement FacbookSDK 2.8 for my website and below is the simplified version of the code.
<button onclick="logout()">Logout</button>
<button onclick="login()">LogIn</button>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
setTimeout(() => {
window.fbAsyncInit = () => {
FB.init({
appId: 'xxxxxxx', //My app id here
cookie: true, // enable cookies to allow the server to access
// the session
xfbml: true, // parse social plugins on this page
version: 'v2.8' // use graph api version 2.8
});
checkFBLoginStatus();
}
})
function checkFBLoginStatus() {
FB.getLoginStatus((response) => {
console.log(response)
});
}
function logout() {
FB.logout(function(response) {
console.log(response)
})
}
function login() {
FB.login(function(response) {
console.log(response)
FB.api('/me?fields=id,email,name', function(response) {
console.log(JSON.stringify(response));
});
}, {
scope: 'email'
})
}
function onLoginSuccess() {
FB.getLoginStatus(function(response) {
console.log(response)
})
}
</script>
I am getting the response on logout and login
Here are my questions
On FB.api call i am getting only ID and Name whereas i need user email to set as an unique user identifier.
When is the condition i can achieve not_authorized. I am getting status 'connected' if i login and 'unknown' if i logout. I am not able to reproduce the condition un_authorized, so that i could code for it.
You should use the ID of the user to identify him, not the email. Users do not have to have an email, they can also use their phone number to login. Make sure you get asked for the email permission in the login process/popup. Also, use this form instead:
FB.api('/me', {fields: 'id,email,name'}, function(response) {
console.log(JSON.stringify(response));
});

Facebook app is just posting content on my wall?

I have created a Facebook app which will share a link to users wall
but the issue is the link is posted on my wall but not on any other user's wall
i have put on live link Link to post on wall app
the code of app that will post on users wall is given below is there anything i need to approve it from the facebook or is there any mistake in my code please i need a real help any one could do ?
waiting for your kind response i am new to the Facebook API
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId: '763390233734216', // App ID from the app dashboard
//channelUrl : '//local.facebook-test/channel.html', // Channel file for x-domain comms
status: true, // Check Facebook Login status
xfbml: true, // Look for social plugins on the page
oauth: true // Enable oauth authentication
});
// Additional initialization code such as adding Event Listeners goes here
FB.login(function(response) {
if (response.authResponse) {
console.log(response.authResponse.accessToken);
var params = {};
params['name'] = 'Seasons Canola';
params['description'] = 'Description';
params['link'] = 'http://vimeo.com/99708842';
FB.api('/me/feed', 'post', params, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
} else {
alert('Not logged in');
}
}, {
scope: 'public_profile,email,publish_actions'
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

facebook api v 1.0 asking for approve permission user_likes

Facebook Logon Dialog show warning message
The following permissions have not been approved for use and are not being shown to people using your app: user_likes.
Submit them for review or learn more.
But according to documentation it shouldn't, because my app created before April 30th, 2014.
Link to app: https://www.facebook.com/brights.com.ua/app_327215967365892
Js code:
window.fbAsyncInit = function () {
FB.init({
appId: FB_APP_ID,
status: true,
cookie: true,
xfbml: true
});
};
(function (d) {
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/ru_RU/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
function facebookLogon(callback, callbackCancel) {
FB.login(function (response) {
if (response.authResponse) {
callback(response.authResponse.accessToken);
} else {
if (callbackCancel) {
callbackCancel();
}
}
}, { scope: FB_PERMISSIONS, privacy: "{ 'value': 'EVERYONE' }" });
};

Access denied while redirecting back to application

This is my implementation of facebook login functionality using Facebook SDK.
<script type="text/javascript">
window.fbAsyncInit = function () {
// Initialize the SDK upon load
FB.init({
appId: '1xxxxxxxxxxxx', // App ID
channelUrl: '//' + window.location.hostname + '//Home/Index',
scope: 'id,name,gender,user_birthday,email,first_name,last_name,access_token',
status: true,
cookie: true,
xfbml: true
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', OnLogin);
};
// This method will be called after the user login into facebook.
function OnLogin(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
$('#AccessToken').attr('value', access_token);
$("#AuthenticatedWithFacebook").attr("value", true);
FB.api('/me', LoadValues);
}
else {
$("#AuthenticationToken").removeAttr('value');
$("#AuthenticatedWithFacebook").attr("value", false);
}
}
//This method will load the values to the labels
function LoadValues(me) {
if (me.id) {
$("#UserId").attr("value", me.id);
$("#AuthenticationToken").attr("value", "facebook/" + me.id);
$("#FirstName").attr("value", me.first_name);
$("#LastName").attr("value", me.last_name);
$("#EmailAddress").attr("value", me.email);
}
}
</script>
<script>(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=1xxxxxxxxxxxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Login Pop-Up works just fine but after logging in I'm getting following exception:
Exception was thrown at line 38, column 184 in http://static.ak.fbcdn.net/rsrc.php/v2/yQ/r/Yax99g-1J46.js
0x80070005 - JavaScript runtime error: Access is denied.
I'm testing here on localhost (http://localhost:59777/) which I have configured in my Facebook application as well.

facebook popup blocking on feed share

I have the following feature where the user can share a feed. The below code gets block by pop up blockers on most browsers. I've seen several post on stack overflow about this issue. One recommended using the onclick which i've tried. I've noticed that if my facebook sdk fails i don't get the popup block. What is the best plan of attack. I'm using php.
<a class="facebook" href="#" onclick='loadSdk(); return false;'></a>
<script>
function loadSdk(){
window.fbAsyncInit = function() {
FB.init({
appId : '123', // App ID
channelUrl : 'http://mysite.com/facebook', // Channel File
// status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
if (typeof facebookInit == 'function') {
facebookInit();
}
FB.api('/me', function(user) {
if (user) {
var image = document.getElementById('image');
image.src = 'https://graph.facebook.com/' + user.id + '/picture';
var name = document.getElementById('name');
name.innerHTML = user.name
}
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
}
function facebookInit(){
var publish = {
method: 'feed',
message: '',
name: '',
caption: '',
description: (
),
link: 'http://mysite.com/',
picture: 'http://mysite.com/fblogo.png',
actions: [
{ name: '123', link: 'http://www.mysite.com/' }
],
user_message_prompt: 'Share your thoughts'
};
FB.ui(publish, null);
}
</script>
Currently you are loading the SDK onclick – why?
You want to execute the function that opens a popup – facebookInit in your case – onclick.