【问题标题】:Facebook cURL posting as me?Facebook cURL 以我的身份发帖?
【发布时间】:2012-05-17 09:01:54
【问题描述】:

创建 Facebook 应用程序

使用 cURL 从应用程序发布消息,但它似乎是我发布的?我怎样才能从应用程序发布,这是我的 cURL

    $attachment =  array(
    'access_token' => $token,
    'message' => '$message',
    'name' => '$name',
    'link' => '$link',
    'description' => '$description',
    'picture'=> '$picture',
    'actions' => json_encode(array('name' => '$name2','link' => '$link2'))
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$pId.'/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
$result = curl_exec($ch);
curl_close ($ch);

帖子有效,但看起来好像我发布了它而不是应用程序,建议?!

【问题讨论】:

  • 您是如何获得$token 的? $pId 的 ID 是什么?
  • 我保存在数据库中的令牌,pId 是 facebook 人员 ID
  • 你保存的令牌是给特定用户的,我想?我对代表用户将其发布到用户的提要中并不感到惊讶,但我不知道如何(或是否可以)作为应用发布。
  • 愚蠢的问题:您是否检查了 FB 中的应用设置以确保所有字段都正确填写?
  • 你为什么使用 curl 而不是 php sdk? sdk 向 post 请求添加了一些额外的参数,如使用的 sdk 等参数,以及其他一些参数以及您应该感兴趣的 api_key 和 app_id(它们是相同的)。尝试添加这些。

标签: php facebook facebook-graph-api curl


【解决方案1】:

这是对我有用的代码

$file = 'image.jpg';
$args = array(
   'message' => 'Photo from application',
    'access_token'=>urlencode('Your Access token'),
);
$args[basename($file)] = '@'.realpath($file);

$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$result = curl_exec($ch);
curl_close ($ch);

也许对你有帮助。

【讨论】:

  • 对不起大家,我是个白痴。我确定您的代码可以正常工作,我的代码也可以正常工作-我只是忘记了我在我的 Facebook 下创建了该应用程序,而不是该应用程序的 Facebook,这就是它以我的身份发布的原因。原谅我笨!我想我应该多睡点哈哈
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-19
  • 2015-12-27
  • 1970-01-01
  • 1970-01-01
  • 2015-11-23
  • 2022-11-08
相关资源
最近更新 更多