I am setting up for posting story on facebook but I am getting following alert:
You, or this app's Open Graph Test User, must have published this action at least once.
I am getting id in the response but when I am clicking on that I am redirecting to "Page not found".
Here is my code :
FB.api(
'me/objects/appnamespace:objecttype',
'post',
{
object :{
app_id: myappId,
objectype: myurl,
title: "Sample Organization",
image: mylogo,
description: ""
}
},
function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'<a href=\"https://www.facebook.com/me/activity/' +
response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>';
}
}
);
Related
$http.post(myurl, myreq).success(function(apiReply) {
if (! checkApiResponse(apiReply)){
console.log("failed to run action with error: " + apiReply.retcode + " " + apiReply.retbody)
return false
} else {
callback(apiReply)
}
}).error(function(data, status) {
var errmsg = "handle api request failed with status: "
errmsg += status + ", error response: " + data
console.log(errmsg)
ons.notification.alert({
//title: "错误",
//message: '连接服务器失败',
title: "提示",
message: "请检查您的网络环境",
buttonLabel: ['确认']
});
});
}
here is my way to post data ,when using http url,it works fine,but doesn't work when i use https url, what should i do?
I know this question was asked already often, but I have been trying to fix this problem for like more than 6 hours now and I could use a little help. Error Message: Insufficient permssion to post to target on behalf of the viewer.
I'm trying to post as page, my code so far:
var pageID = "myPage";
FB.init({
appId: "myId",
secret: "mySecret",
status: true,
cookie: true,
});
function postToFeed() {
FB.login(function(response) {
FB.api('/me/accounts', function(response) {
var accessToken = "";
var data = response.data;
for (var i=0; i<data.length; i++) {
if (data[i].id == pageID) {
accessToken = data[i].access_token;
}
}
if (accessToken == "") {
alert("You are not allowed to post.");
}
else {
console.log(accessToken);
FB.api('/' + pageID + '/feed', 'post', {
message : "test",
link : 'Link',
picture : 'Imageurl',
name : 'test',
to : pageID,
from : pageID,
description : 'test'
}, function(response) {
if (!response || response.error) {
alert(JSON.stringify(response.error));
} else {
alert('Post ID: ' + response.id);
}
});
}
});
}, {scope: 'publish_actions,manage_pages,public_profile'});
}
When I echo my accessToken via console and copy the accessToken inside this code, it works perfectly. But that's not an solution because I want it to be dynamic:
function postToFeed() {
FB.login(function(response) {
FB.api('/' + pageID + '/feed', 'post', {
access_token: 'theAcccessToken',
message: "I'm a Page!",
}, function(response) {
console.log(response);
}
);
}, {scope: 'publish_actions,manage_pages,public_profile'});
}
And this does not work? (not sure what you want to do with the "to" and "from" parameters, so i removed them)
FB.api('/' + pageID + '/feed', 'post', {
message : 'test',
link : 'Link',
picture : 'Imageurl',
name : 'test',
description : 'test',
access_token: accessToken
}
The most important thing: You need publish_pages to post "as Page", not publish_actions.
Btw, a small optimization:
for (var i = 0; i < data.length; i++) {
if (data[i].id === pageID) {
accessToken = data[i].access_token;
break;
}
}
if (accessToken === "") {
alert("You are not allowed to post.");
}
...always use typesafe comparison :)
I can't seem to check if a logged in user likes a specific Facebook Business page(URL). This keeps coming back as undefined. Notice anything wrong here?
function postLike() {
FB.api(
'https://graph.facebook.com/me/og.likes',
'get',
{ id: objectToLike,
privacy: {'value': 'SELF'} },
function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'Business page is ' +
response.object + '</a>';
}
}
);
}
I'm trying to post a messsage to a wall using FB.api
My perms are: 'email, read_stream, publish_stream' and my code is:
FB.getLoginStatus(function(response){
if(response.session) {
var accessToken = response.session.access_token;
var tokenUrl = "https://graph.facebook.com/me/feed?access_token=" + accessToken + "&callback=?";
var shareUserId = document.getElementById("shareHidden").value;
var shareTxtAreaMsg = document.getElementById("shareTxtArea").value;
console.log("friends user Id: " + shareUserId + " & " + "message: " + shareTxtAreaMsg);
var data = {
message: "shareTxtAreaMsg",
display: 'iframe',
caption: "Caption",
name: "Name",
picture: 'http://someDomain.com/Dev/img/share-force-wall-img.jpg',
link: "http://www.facebook.com/pages/someapp/XXXXXXXXXXX?sk=app_XXXXXXXXXXXXXX", // Go here if user click the picture
description: "Description field",
actions: [{ name: 'action_links text!', link: 'some link' }],
}
console.log(accessToken);
FB.api(tokenUrl, 'post', data, function(response){
if (response)
{
//console.log(response);
if (response.error)
{
console.log(response.error.message);
}
else
{
if (response.id)
console.log("Posted as post_id "+response.id);
else if (response.post_id)
console.log("Posted as post_id "+response.post_id);
else
console.log("Unknown Error");
}
}
});
}
});
When when try to post the message I'm getting a "(#3) App must be on whitelist" returned. Why is this happening?
Try FB.api('/me/feed'... instead of tokenUrl because FB.api will automatically add the full url prefix.
I'm using login, registration Facebook API with JavaScript in a WordPress plugin. I got this error
json.stringify is not a function error at JavaScript.
What is the issue? I use this code:
<div id="fb-root"></div>
<script type="text/javascript">
var button;
var userInfo;
window.fbAsyncInit = function() {
FB.init({ appId: '154333274632806',
status: true,
cookie: true,
xfbml: true,
oauth: true});
showLoader(true);
function updateButton(response) {
button = document.getElementById('fb-auth');
userInfo = document.getElementById('user-info');
if (response.authResponse) {
//user is already logged in and connected
FB.api('/me', function(info) {
login(response, info);
});
button.onclick = function() {
FB.logout(function(response) {
logout(response);
});
};
}
else {
//user is not connected to your app or logged out
button.innerHTML = 'Login';
button.onclick = function() {
showLoader(true);
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(info) {
login(response, info);
});
} else {
//user cancelled login or did not grant authorization
showLoader(false);
}
}, {scope:'email,user_birthday,status_update,publish_stream,user_about_me'});
}
}
}
// Run once with current status and whenever the status changes.
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
function login(response, info){
if (response.authResponse) {
var accessToken = response.authResponse.accessToken;
userInfo.innerHTML = '<img src="https://graph.facebook.com/' + info.id + '/picture">' + info.name
+ "<br /> Your Access Token: " + accessToken;
button.innerHTML = 'Logout';
showLoader(false);
document.getElementById('other').style.display = "block";
}
}
function logout(response){
userInfo.innerHTML = "";
document.getElementById('debug').innerHTML = "";
document.getElementById('other').style.display = "none";
showLoader(false);
}
//stream publish method
function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){
showLoader(true);
FB.ui(
{
method: 'stream.publish',
message: '',
attachment: {
name: name,
caption: '',
description: (description),
href: hrefLink
},
action_links: [
{ text: hrefTitle, href: hrefLink }
],
user_prompt_message: userPrompt
},
function(response) {
showLoader(false);
});
}
function showStream(){
FB.api('/me', function(response) {
//console.log(response.id);
streamPublish(response.name, 'I like the articles of Thinkdiff.net', 'hrefTitle', 'http://thinkdiff.net', "Share thinkdiff.net");
});
}
function share(){
showLoader(true);
var share = {
method: 'stream.share',
u: 'http://thinkdiff.net/'
};
FB.ui(share, function(response) {
showLoader(false);
console.log(response);
});
}
function graphStreamPublish(){
showLoader(true);
FB.api('/me/feed', 'post',
{
message : "I love thinkdiff.net for facebook app development tutorials",
link : 'http://ithinkdiff.net',
picture : 'http://thinkdiff.net/iphone/lucky7_ios.jpg',
name : 'iOS Apps & Games',
description : 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!'
},
function(response) {
showLoader(false);
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
function fqlQuery(){
showLoader(true);
FB.api('/me', function(response) {
showLoader(false);
//http://developers.facebook.com/docs/reference/fql/user/
var query = FB.Data.query('select name, profile_url, sex, pic_small from user where uid={0}', response.id);
query.wait(function(rows) {
document.getElementById('debug').innerHTML =
'FQL Information: '+ "<br />" +
'Your name: ' + rows[0].name + "<br />" +
'Your Sex: ' + (rows[0].sex!= undefined ? rows[0].sex : "") + "<br />" +
'Your Profile: ' + "<a href='" + rows[0].profile_url + "'>" + rows[0].profile_url + "</a>" + "<br />" +
'<img src="' + rows[0].pic_small + '" alt="" />' + "<br />";
});
});
}
function setStatus(){
showLoader(true);
status1 = document.getElementById('status').value;
FB.api(
{
method: 'status.set',
status: status1
},
function(response) {
if (response == 0){
alert('Your facebook status not updated. Give Status Update Permission.');
}
else{
alert('Your facebook status updated');
}
showLoader(false);
}
);
}
function showLoader(status){
if (status)
document.getElementById('loader').style.display = 'block';
else
document.getElementById('loader').style.display = 'none';
}
</script>
<h3>New JavaScript SDK & OAuth 2.0 based FBConnect Tutorial | Thinkdiff.net</h3>
<button id="fb-auth">Login</button>
<div id="loader" style="display:none">
<img src="ajax-loader.gif" alt="loading" />
</div>
<br />
<div id="user-info"></div>
<br />
<div id="debug"></div>
<div id="other" style="display:none">
Publish Wall Post |
Share With Your Friends |
Publish Stream Using Graph API |
FQL Query Example
<br />
<textarea id="status" cols="50" rows="5">Write your status here and click 'Status Set Using Legacy Api Call'</textarea>
<br />
Status Set Using Legacy Api Call
</div>
You can find a link to the code for json.stringify here -
http://www.json.org/js.html
If you add that to your code then the error should go away.
Alternatively, you could add a reference to this script to your code -
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
What browser are you using? Not every browser supports native JSON parsing like you are trying. Also, it should be:
JSON.stringify