Мне нужно опубликовать на странице Facebook, используя API.Публикация на страницу Facebook
Я зарегистрировался как страница, и я использую приложение с некоторой конфигурацией.
var access;
function statusChangeCallback(response) {
console.log('statusChangeCallback');
access = response.authResponse.accessToken;
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app and Facebook.
testAPI();
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : '679960325437732',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.2' // use version 2.2
});
// Now that we've initialized the JavaScript SDK, we call
// FB.getLoginStatus(). This function gets the state of the
// person visiting this page and can return one of three states to
// the callback you provide. They can be:
//
// 1. Logged into your app ('connected')
// 2. Logged into Facebook, but not your app ('not_authorized')
// 3. Not logged into Facebook and can't tell if they are logged into
// your app or not.
//
// These three cases are handled in the callback function.
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// 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/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
var page;
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
FB.api('/369847826459197', function(response) {
page = response;
$('#facebook-login-button').css('display', 'none');
document.getElementById('status').innerHTML =
'You are Logged in Facebook as ' + response.name + '!';
});
}
function post_to_facebook(link, message, photo) {
var wallPost = {
access_token: page.access_token,
link: link,
message: message,
picture: photo
};
FB.api("me/feed", "post", wallPost, function (response) {
if (!response || response.error) {
console.log(response);
alert('Failure! ' + response.status + ' You may logout once and try again');
} else {
alert('Success! Post ID: ' + response);
}
});
}
Я пытаюсь разместить на форме представить это код на представить:
$('#add_new').click(function() {
var formData = new FormData($('#add_new_form')[0]);
formData.append("arabic_body", tinyMCE.get('ar_body').getContent());
formData.append("english_body", tinyMCE.get('en_body').getContent());
var url = getBaseUrl() + '/admin/add_new';
$.ajax({
url : url, // Controller URL
type : 'POST',
data : formData,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
dataType: 'JSON',
processData: false,
success : function(data) {
$('#nothing').fadeOut('slow');
console.log(data);
post_to_facebook(getBaseUrl() + '/Pages/view_new/' + data[0].id, data[0].ar_title, getBaseUrl() + '/news/' + data[0].img);
$('#new').prepend('<tr id="row' + data[0].id + '"><td>' + data[0].id + '</td><td><a href="Pages/view_new/' + data[0].id + '">' + data[0].ar_title.substr(0,30)+' ...' + '</a></td><td>' + data[0].type_name + '</td><td>' + data[0].date_created + '</td><td><span style="color: red; cursor: pointer;" onclick="delete_new($(this));" id="del' + data[0].id + '" class="delete_new">✘</span></td></tr>');
},
complete: function() {
$('#shownew').trigger('click');
$('#add_new_form')[0].reset();
}
});
return false;
});
UPDATE
это пост, но как пользователь, а не страницы.
так .... любые ошибки? вы уже отлаживали свой код? где проблема в точности? – luschn
@luschn я отлаживаю его, и он публикуется на странице, как я, как пользователь, но не как facebook page и iam, пытаясь сделать сообщение приложения как страницу. –
хорошо, это важная часть, на самом деле это единственная релевантная информация. я напишу ответ. – luschn