Facebook Custom Stories not appearing in activity feed - facebook

I'm using Facebook's JavaScript SDK to create a custom story.
FB.login(function() {
FB.api(
'me/' + fb_app_namespace + ':review_a_book',
'post',
{
book: "http://samples.ogp.me/199815506812566"
},
function(response) {
// handle the response
if (!response) {
alert('Error occurred.');
} else if (response.error) {
$('#result').text('Error: ' + response.error.message);
} else {
$('#result').html('<a href=\"https://www.facebook.com/me/activity/' +
response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>');
}
}
);
}, {scope: 'publish_actions'});
The Custom Story 'Review A Book' is setup in the App Dashboard and the JS fires correctly without error. The problem comes in when I try to view the Activity in my Activity Log. It just isn't there. Also the link generated presents me with a page that simple says 'This content is currently unavailable'.
The Application is Public, and at the very least should work with me as an Admin or Developer.
Any help would be appreciated.

Related

How to use facebook API to post to my own page

I had the ability to post from my website to my page some time ago, it seems there have been some changes made to the API since then now when I use the below snippets I get the error message
{"message":"(#100) Only owners of the URL have the ability to specify the picture, name, thumbnail or description params.","type":"OAuthException","code":100,"fbtrace_id":"AsGjV6ebkihnC60tRtHM4f3"}
Code
function postToFeed(id, desc, name) {
var page_id = ************;
var app_id = ************;
FB.api('/' + page_id, {
fields : 'access_token'
}, function(resp) {
console.log(resp);
if (resp.access_token) {
FB.api('/' + page_id + '/feed', 'post', {
message : desc,
link : 'https://link',
name : name,
from : page_id,
description :'',
access_token : resp.access_token
}, function(response) {
if (!response || response.error) {
alert(JSON.stringify(response.error));
} else {
alert('Post ID: ' + response.id);
}
});
}
});
Yes, like the error message suggests, this changed some time ago. See the respective section
Custom Link Page Post Image
in the docs for more information: https://developers.facebook.com/docs/graph-api/reference/v3.3/page/feed
You can of course also just remove the custom description parameter.

How to get facebook post by a user using graph api?

I have tried following code to get posts from a user using my app. But, I am getting error occurred in second case while trying to post to user's wall and in retrieving posts, i have only data and pagination.
FB.api('/platform/posts', { limit: 3 }, function(response) {
console.log('Good to see you, ' + response.length);
for (var i=0, l=response.length; i<l; i++) {
var post = response[i];
console.log('Good to see you, ' + post);
/*if (post.message) {
alert('Message: ' + post.message);
} else if (post.attachment && post.attachment.name) {
alert('Attachment: ' + post.attachment.name);
}*/
}
});
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
what's going wrong?
In the second block, alert, "Error occurred" is being displayed. And in the first block, following error occurred:
__d("sdk.ErrorHandling", ["sdk.feature","ManagedError","sdk.Runtime","sdk.Scribe","UserAgent","wrapFunction"],function(a,b,c,d,e,f){var g=b('sdk.feature'),h=b('ManagedError'),i=b('sdk.Runtime'),j=b('sdk.Scribe'),k=b('UserAgent'),l=b('wrapFunction'),m=g('error_handling',false),n='';function o(u){var v=u._originalError;delete u._originalError;j.log('jssdk_error',{appId:i.getClientID(),error:u.name||u.message,extra:u});throw v;}function p(u){var v={line:u.lineNumber||u.line,message:u.message,name:u.name,script:u.fileName||u.sourceURL||u.script,stack:u.stackTrace||u.stack};v._originalError=u;if(k.chrome()&&/([\w:\.\/]+\.js):(\d+)/.test(u.stack)){v.script=RegExp.$1;v.line=parseInt(RegExp.$2,10);}for(var w in v)(v[w]==null&&delete v[w]);return v;}function q(u,v){return function(){if(!m)return u.apply(this,arguments);try{n=v;return u.apply(this,arguments);}catch(w){if(w instanceof h)throw w;var x=p(w);x.entry=v;var y=ES5(Array.prototype.slice.call(arguments),'map',true,function(z){var aa=Object.prototype.toString.call(z);return (/^\[object (String|Number|Boolean|Object|Date)\]$/).test(aa)?z:z.toString();});x.args=ES5('JSON','stringify',false,y).substring(0,200);o(x);}finally{n='';}};}function r(u){if(!u.__wrapper)u.__wrapper=function(){try{return u.apply(this,arguments);}catch(v){window.setTimeout(function(){throw v;},0);return false;}};return u.__wrapper;}function s(u,v){return function(w,x){var y=v+':'+(n||'[global]')+':'+(w.name||'[anonymous]'+(arguments.callee.caller.name?'('+arguments.callee.caller.name+')':''));return u(l(w,'entry',y),x);};}if(m){setTimeout=s(setTimeout,'setTimeout');setInterval=s(setInterval,'setInterval');l.setWrapper(q,'entry');}var t={guard:q,unguard:r};e.exports=t;});
Thanks

Facebook Open Graph: How to Post User Message with Custom Action

The Facebook tutorials suggest that you can add a user comment to a custom action in a Facebook App. The example javascript function for posting is:
<script type="text/javascript">
function postCook()
{
FB.api(
'/me/[YOUR_APP_NAMESPACE]:cook',
'post',
{ recipe: 'http://fbwerks.com:8000/zhen/cookie.html' },
function(response) {
if (!response || response.error) {
alert('Error occurred');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
}
</script>
I have an "Endorse" action defined with the object "Local Business". Everything is working. Now I want to give the user the option to add a user message to their endorsement but I can not find any help in Facebook docs on how to implement this in the api (the above code). Any help?
You need to specify the 'message' parameter when publishing the action. For example,
<script type="text/javascript">
function postCook(userMessage)
{
FB.api(
'/me/[YOUR_APP_NAMESPACE]:cook',
'post',
{ recipe: 'http://fbwerks.com:8000/zhen/cookie.html',
message: userMessage },
function(response) {
if (!response || response.error) {
alert('Error occurred');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
}
</script>
will submit userMessage as a user provided message on the action.
The full list of supported parameters for the OpenGraph publishing API is available here: https://developers.facebook.com/docs/technical-guides/opengraph/publish-action/#create

How to find out who has published a post using my OG action

Hoping someone can point me in the right direction.
I have an open graph action that has finally been approved and is active on my app now. Is there any way to track who publishes a post using my OG action from within my app?
Here is the code I'm using for my action:
<script type="text/javascript">
function postEndorse()
{
FB.api(
'/me/namespace:endorse',
'post',
{ photo: '<?php the_permalink(); ?>' },
function(response) {
if (!response || response.error) {
alert('Error Occurred' + response + " " + response.error);
} else {
alert('Thank you!');
}
});
}
</script>
I am requesting the publish_actions permissions when people log in.
Thanks
The response in your JavaScript code above has the id of the action.
{
id: “{action-instance-id}”
}
You need to store your actions via database or otherwise. Once you have that you can make a call against it
/action-instance-id?fields=from.fields(id)
Which will give a response such as
{
"from": {
"id": "{user-id}"
},
"id": "{action-instance-id}"
}
There are many ways to store this data, one way would be AJAX to PHP/MySQL.
I suggest reading up on it. The following hasn't been tested, just gives an idea of how to send the data across. Think of it as pseudocode
Add jQuery to the <head>
<script src="jquery.js"></script>
Send the id of the user, like
<script type="text/javascript">
function postEndorse()
{
FB.api(
'/me/namespace:endorse',
'post',
{ photo: '<?php the_permalink(); ?>' },
function(response) {
if (!response || response.error) {
alert('Error Occurred' + response + " " + response.error);
} else {
FB.api(
response.id + "?fields=from.fields(id)",
function(resp) {
if (!resp || resp.error) {
alert('Error Occurred' + resp + " " + resp.error);
} else {
$.ajax({
type: "POST",
url: "fbdata.php",
data: { id: resp.from.id, actionid: resp.id }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
}
});
}
});
}
</script>
Then in fbdata.php something like
<?php
include("database.inc.php");
mysql_connect($server,$username,$password);
#mysql_select_db($database) or die( "Unable to select database");
$id = mysql_real_escape_string($_POST['id']);
$actionid = mysql_real_escape_string($_POST['actionid']);
$database_entry = "INSERT INTO Actions (Id, Action) VALUES ('$id', '$actionid') ;
mysql_query($database_ntry) or die(mysql_error());
mysql_close();
?>
References that you should read
http://api.jquery.com/jQuery.ajax/
http://www.php.net/manual/en/mysql.examples-basic.php
What about if you change
/me/namespace:endorse to /users facebook id/namespace:endorse Then you can store the facebook id of the person and then track them back using that.

Sencha Touch and Facebook button

I need to create a button to submit a comment on Face Book wall.
I am using MVC in Sencha touch and in my controller I use a function as
facebookComment: function()
{
--------
}
This function is to be called when a button is pressed.
Can any body please throw some light on how to go about this?
i am using following code to post on friends wall see if it is useful to you or not
var postParams = {
method: 'stream.publish'
, target_id: friend_id
, display: 'popup'
, message: message
, user_message_prompt: "Post message!"
}
FB.api(postParams, function(response) {
if(response.error_code || !response) {
to handle error
}
});
or refer this link https://developers.facebook.com/docs/reference/rest/stream.publish/
Well, first you should already be using the Javascript SDK. Then just issue a HTTP POST request to the feed connection of the current user using the FB.api() method with the message field set to your comment:
var body = comment_var;
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
Obviously, should be taking care of the user login status (maybe using the method FB.getLoginStatus()).