Facebook API 致命错误
我使用的一些代码出现以下错误。错误是
[2011 年 6 月 27 日星期一 16:44:04] [错误] [客户端 194.116.198.179] PHP 致命 错误:调用成员函数 api() 对非对象 /public_html/users/fbmain.php 上线 89
我正在使用的代码在将其变成函数之前工作正常。第 89 行以 $statusUpdate 开头。
function post_basic_status($msg){
try {
$statusUpdate = $facebook->api("/$user/feed", 'post', array('message'=> $msg));
} catch (FacebookApiException $e) {
d($e);
}
}
从网上查找我找不到任何解决方案。这有什么明显的问题吗
I am getting the following error with some code that I am using. The error is
[Mon Jun 27 16:44:04 2011] [error]
[client 194.116.198.179] PHP Fatal
error: Call to a member function
api() on a non-object in
/public_html/users/fbmain.php on line
89
The code I am using worked ok before I made it into a function. Line 89 begins with $statusUpdate.
function post_basic_status($msg){
try {
$statusUpdate = $facebook->api("/$user/feed", 'post', array('message'=> $msg));
} catch (FacebookApiException $e) {
d($e);
}
}
From looking online I cannot find any solution to this. IS there anything glaringly wrong with this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题...直到您发布有关从函数调用 api 的文章。
事实证明 Facebook API 不喜欢在函数中使用。
需要在页面加载时调用它。
I've had the same issue... until your post about calling the api from a function.
It turns our that Facebook API doesn't like to be used in a function.
It needs to be called on page load.
我遇到了同样的问题,一直摸不着头脑,直到我读到这篇文章...问题是 $facebook 在函数外部声明,并在函数内部被引用,但未被识别。
您需要将 $facebook 句柄作为参数传递,或者添加行 GLOBAL $facebook;在函数的顶部。
I had the same problem and was scratching my head until I read this post... the problem is that $facebook is declared outside the function and is being referenced inside the function but is not recognized.
You either need to pass the $facebook handle in as a parameter OR add the line GLOBAL $facebook; at the top of the function.
添加行 GLOBAL $facebook;在函数的顶部。它对我有用:)
add the line GLOBAL $facebook; at the top of the function. it worked for me :)