2012-05-30 44 views
1

我真的很苦恼Facebook的api。 A创建了一个应用程序,一个对象一个动作,我想测试在我的流中发布,(我知道公开发布必须由Facebook授权,但作为我的应用程序的管理员,我被允许测试它)。但它不行。这里的脚本:使用Java脚本的Facebook API发布操作sdk

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" 
    xmlns:fb="https://www.facebook.com/2008/fbml"> 
<head prefix="og: http://ogp.me/ns# subhinajjar: 
       http://ogp.me/ns/apps/subhinajjar#"> 
<title>OG Tutorial App</title> 
<meta property="fb:app_id" content="452488354765730" /> 
<meta property="og:type" content="subhinajjar:article" /> 
<meta property="og:title" content="3eesho" /> 
<meta property="og:image" content="https://3eesho.com/public/admin/logo.png" /> 
<meta property="og:description" content="3eesho reading club" /> 
<meta property="og:url" content="https://3eesho.com/"> 

<script type="text/javascript"> 
function postreads() 
{ 
    FB.api(
    '/me/subhinajjar:read?article', 
    'post', 
    { article: 'https://3eesho.com/articles/2346/-' }, 
    function(response) { 
     if (!response || response.error) { 
      alert('Error occured'); 
     } else { 
      alert('read was successful! Action ID: ' + response.id); 
     } 
    }); 
} 
</script> 
</head> 
<body> 
<div id="fb-root"></div> 
<script> 
window.fbAsyncInit = function() { 
    FB.init({ 
    appId  : '452488354765730', // App ID 
    status  : true, // check login status 
    cookie  : true, // enable cookies to allow the server to access the session 
    xfbml  : true // parse XFBML 
    }); 
}; 

// Load the SDK Asynchronously 
(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/en_US/all.js"; 
    d.getElementsByTagName('head')[0].appendChild(js); 
}(document)); 
</script> 

<h3>Stuffed Cookies</h3> 
<p> 
<img title="3eesho reading club" 
    src="https://3eesho.com/public/admin/logo.png" 
    width="550"/> 
</p> 

<br> 
<form> 
<input type="button" value="read" onclick="postreads()" /> 
</form> 

<fb:activity actions="subhinajjar:read"></fb:activity> 

</body> 
</html> 

但我总是有这样的消息:错误协议。这让我疯狂。 我希望任何机构可以修改这段代码给我。

回答

0

尝试将FB.api中的API调用的URL更改为:​​(即删除文章,因为您将其作为数据发布)。

response区块中,提醒错误以查看将操作发布到Facebook时实际发生的情况。你的代码应该是这样的:

function postreads() 
{ 
    FB.api(
    '/me/subhinajjar:read', 
    'post', 
    { article: 'https://3eesho.com/articles/2346/-' }, 
    function(response) { 
     if (!response || response.error) { 
      // show the error 
      alert(response.error); 
     } else { 
      alert('read was successful! Action ID: ' + response.id); 
     } 
    }); 
} 

如果还是不行,请尝试使用内置的阅读行动:

FB.api(
    '/me/news.reads', 
    'post', 
    { article: 'https://3eesho.com/articles/2346/-' }, 
    function(response) { 
     if (!response || response.error) { 
      // show the error 
      alert(response.error); 
     } else { 
      alert('read was successful! Action ID: ' + response.id); 
     } 
    }); 
} 
+0

这个拖方式行不通。我想我有另一个问题,因为response.id的值总是:undefined – user1326956

相关问题