gpt4 book ai didi

javascript - Facebook API - 发布到时间线

转载 作者:行者123 更新时间:2023-11-28 03:35:58 26 4
gpt4 key购买 nike

我知道这不会那么困难;也许我会以错误的方式解决这个问题。希望你能帮助我。

我有一个网站需要能够将字符串发布到某人的 Facebook 时间轴。

我已经让他们正确登录,但我没有找到任何工作代码来在他们给予许可后将信息提交到他们的时间线。

我按照示例 here 进行了操作没有运气。我有

  • 创建了一个应用
  • 登录 Facebook
  • 使用食谱对象定义了 Cook 操作
  • 使用他们提供的代码在我的网站上创建了一个页面,将 [your_app_id] 替换为我的应用程序 ID
  • 试图发布 cooking Action

但是当我在我的网站上点击他们的示例页面上的 cooking 按钮时,它给了我错误:

No callback passed to the ApiClient for https://graph.facebook.com/me/fblaevents:cook 

发生错误 浏览器警报弹出。

这是我正在使用的示例代码:

<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# fblaevents:
http://ogp.me/ns/apps/fblaevents#">
<title>OG Tutorial App</title>
<meta property="fb:app_id" content="542182755801091" />
<meta property="og:type" content="fblaevents:recipe" />
<meta property="og:title" content="Stuffed Cookies" />
<meta property="og:image" content="http://fbwerks.com:8000/zhen/cookie.jpg" />
<meta property="og:description" content="The Turducken of Cookies" />
<meta property="og:url" content="http://fbwerks.com:8000/zhen/cookie.html">

<script type="text/javascript">
function postCook()
{
FB.api(
'/me/fblaevents:cook',
'post',
{ recipe: 'http://fbwerks.com:8000/zhen/cookie.html' },
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
}
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '542182755801091', // 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="Stuffed Cookies"
src="http://fbwerks.com:8000/zhen/cookie.jpg"
width="550"/>
</p>

<br>
<form>
<input type="button" value="Cook" onclick="postCook()" />
</form>
</body>
</html>

如果有更简单的方法,请指出给我。我不知道我在做什么。

最佳答案

您应该将 JS 代码中的 OG 元标记和食谱 url 替换为您自己的。由于上面的代码只是一个起始代码,而不是一个工作演示(或者可能是但现在链接已经死了)。

此外,由于您收到 Error occurred,因此很可能 response.error 中包含某些内容,因此您应该通过调用控制台方法来检查其值,例如:

if (!response || response.error) {
console.log('Error occured: ', response.error);
} else {

这会给你:

Error occured: Object {type: "Exception", message: "Could not retrieve data from URL.", code: 1660002}

关于javascript - Facebook API - 发布到时间线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14299075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com