how to know where to publish if user account has more than one profile
this may be simple, but I guess it isn't, and really Facebook docs are not really useful since they aren't translate开发者_StackOverflow社区 to my mother language, making hard to achieve my goal.
ok, I have a script to enable my webapp to post to my feed on Facebook, but I've a personal feed, a app page and a test page.
How do I tell my script, based on login that I want to post on my test page and not on my personal profile?
this is the code I'm using to login
var appID = 'MY_APP_ID';
var path = 'https://www.facebook.com/dialog/oauth?';
var queryParams = ['client_id=' + appID, 'redirect_uri=' + dominio, 'response_type=token'];
var query = queryParams.join('&');
var url = path + query;
window.open(url);
//
FB.init({appId: appID, status: true, cookie: true, xfbml: true});
//
var accessToken = "";
FB.Event.subscribe('auth.login', function(response) {
if (response.session) {
accessToken = response.session.access_token;
console.log(accessToken);
} else {
console.log(response);
}
login();
});
FB.Event.subscribe('auth.logout', function(response) {
document.getElementById('login').innerHTML = "";
document.getElementById('login').style.display = "none";
});
FB.getLoginStatus(function(response) {
if (response.session) {
accessToken = response.session.access_token;
console.log(response.session);
} else {
console.log(response);
}
login();
});
function login() {
FB.api('/me/accounts?access_token='+accessToken+'', function(response) {
console.log(response);
if(response.name) {
document.getElementById('login').style.display = "block";
document.getElementById('login').innerHTML = "Ligado ao Facebook como "+response.name;
}
});
$('body').criar_paineis_edicao(accessToken);
}
and this one to actually publish
if(accessToken) {
console.log("com token");
FB.api('/me/feed?access_token='+accessToken+'', 'post', parametros, function(response) {
if (!response || response.error) {
$.each(response.error, function(name, value) {
alert(value);
});
window.location.reload();
} else {
alert('Conteudo também publicado no Facebook');
window.location.reload();
}
});
}
EDIT
console.log(response);
produces this
Object
data:array[2]
0: Object
access_token: "my token"
category: "Computers/Internet"
id: "my first id"
name: "my name"
__proto__: Object
1: Object
access_token: "my token_2"
category: "Application"
id: "my second id"
name: "my name"
__proto__: Object
lenght: 2
Post to /{<id}/feed
where {id} is the page or user id where you want to post - /me will always refer to the user whose access token you're using
精彩评论