Javascript 在用户时间线上发布操作时出现问题
我学习了以下教程: 然后: 但当我尝试发布动作时,我总是得到: 邮件:(#3502)URL xxxxxx处的对象具有og:类型的“网站”属性“article”需要og:类型的对象“mynamespacexxxx:article” 我的源代码:Javascript 在用户时间线上发布操作时出现问题,javascript,facebook-graph-api,facebook-opengraph,Javascript,Facebook Graph Api,Facebook Opengraph,我学习了以下教程: 然后: 但当我尝试发布动作时,我总是得到: 邮件:(#3502)URL xxxxxx处的对象具有og:类型的“网站”属性“article”需要og:类型的对象“mynamespacexxxx:article” 我的源代码: <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xmlns:fb="https://www.facebook.com/2008/fbml"> <
<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# fb: http://ogp.me/ns/fb# xxxxxxxxx: http://ogp.me/ns/fb/xxxxxxxxxx#">
<meta property="fb:app_id" content="xxxxxxxxxxxxxx" />
<meta property="og:type" content="xxxxxxxxxxx:article" />
<meta property="og:url" content="http://xxxxxxxxxxxxx/timeline/redir.php" />
<meta property="og:title" content="Sample Article" />
<meta property="og:description" content="Some Arbitrary String" />
<meta property="og:image" content="http://ogp.me/logo.png" />
<script type="text/javascript">
function read()
{
FB.api('/me/xxxxxxxxxxx:read' +
'?article=http://xxxxxxxxxxxxx/timeline/redir.php&access_token=','post',
function(response) {
var msg = 'Error occured';
if (!response || response.error) {
if (response.error) {
msg += "\n\nType: "+response.error.type+"\n\nMessage: "+response.error.message;
}
alert(msg);
}
else {
alert('Post was successful! Action ID: ' + response.id);
}
});
}
</script>
<style type="text/css">
<!--
.style1 {
font-family: Georgia, "Times New Roman", Times, serif;
color: #0066CC;
font-size: 24px;
}
-->
</style>
</head>
<body>
<span class="style1">This is Open Graph test page Click on <strong>Post To your Timeline</strong> button to test.</span>
<fb:add-to-timeline></fb:add-to-timeline>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'xxxxxxxxxxxxx', cookie:true,
status:true, xfbml:true, oauth:true
});
</script>
<form>
<input type="button" value="Post To Your Timline " onClick="read()" />
</form>
</body>
</html>
函数read()
{
FB.api('/me/xxxxxxxxxx:read'+
"文章,=http://xxxxxxxxxxxxx/timeline/redir.php&access_token=","后",,
功能(响应){
var msg='发生错误';
如果(!response | | response.error){
if(response.error){
msg+=“\n\n键入:”+response.error.type+“\n\n消息:”+response.error.message;
}
警报(msg);
}
否则{
警报(“发布成功!操作ID:”+响应.ID);
}
});
}
这是一个打开的图形测试页面,单击发布到您的时间线按钮进行测试。
FB.init({
appId:'xxxxxxxxxxxx',cookie:true,
状态:true,xfbml:true,oauth:true
});
尝试查看Facebook所看到的内容,并更新Facebook的缓存。当我的应用程序试图在我的时间线上发布opengraph对象时,我遇到了这个问题
在我的例子中,原因是服务器端重定向到我试图发布的对象的facebook画布页面。因为对象页面是在facebook上的iFrame中呈现的,所以它的og:type不可见,返回的是facebook页面的og:type
我通过为我的对象创建一个最小的页面模板来解决这个问题,该模板只包含opengraph内容和一个指向实际对象页面的javascript重定向