使用 cURL PHP 发布到 Facebook 用户的留言墙

发布于 2024-11-03 18:43:56 字数 427 浏览 1 评论 0原文

我正在存储 facebook 用户 ID 和访问令牌。我可以将此信息发布到选定用户的留言墙上吗?此处可以找到以下代码: http://developers.facebook.com/docs/reference/api/post/ 我只是不确定如何用 php 运行它。

curl -F 'access_token=$accessToken' \
     -F 'message=Check out this funny article' \
     -F 'link=http://www.example.com/article.html' \
     https://graph.facebook.com/$facebookid/feed

I'm storing facebook userid's and access tokens. Can i post to a selected user's wall with this information? The following code is found here: http://developers.facebook.com/docs/reference/api/post/
I'm just not sure how to run it with php.

curl -F 'access_token=$accessToken' \
     -F 'message=Check out this funny article' \
     -F 'link=http://www.example.com/article.html' \
     https://graph.facebook.com/$facebookid/feed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只怪假的太真实 2024-11-10 18:43:56
$attachment =  array(
'access_token' => $token,
'message' => $msg,
'name' => $title,
'link' => $uri,
'description' => $desc,
'picture'=>$pic,
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/fbnameorid/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);
$attachment =  array(
'access_token' => $token,
'message' => $msg,
'name' => $title,
'link' => $uri,
'description' => $desc,
'picture'=>$pic,
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/fbnameorid/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);
月野兔 2024-11-10 18:43:56

使用 Facebook SDK。这比自己处理CURL要好得多。

Use Facebook SDK. It's much better than handling CURL by yourself.

风渺 2024-11-10 18:43:56

我尝试了 cURL 方法,但我不知道 $action_name 和 $action_link 应该更改为什么。

<?php
require_once("facebooksdk/facebook.php");
require_once('config.php');

$facebook = new Facebook(array(
'appId'  => $appId,
'secret' => $appSecret,
'cookie' => true
));

$access_token = $facebook->getAccessToken();
echo $access_token;
$msg = "testmsg";
$title = "testt";
$uri = "http://somesite.com";
$desc = "testd";
$pic = "http://static.adzerk.net/Advertisers/d18eea9d28f3490b8dcbfa9e38f8336e.jpg";
$attachment =  array(
'access_token' => $access_token,
'message' => $msg,
'name' => $title,
'link' => $uri,
'description' => $desc,
'picture'=>$pic,
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/me/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);


?>

我成功获取了访问令牌,所以我只需要这两个参数。

I tried the cURL method but I don't know what should be $action_name and $action_link changed to.

<?php
require_once("facebooksdk/facebook.php");
require_once('config.php');

$facebook = new Facebook(array(
'appId'  => $appId,
'secret' => $appSecret,
'cookie' => true
));

$access_token = $facebook->getAccessToken();
echo $access_token;
$msg = "testmsg";
$title = "testt";
$uri = "http://somesite.com";
$desc = "testd";
$pic = "http://static.adzerk.net/Advertisers/d18eea9d28f3490b8dcbfa9e38f8336e.jpg";
$attachment =  array(
'access_token' => $access_token,
'message' => $msg,
'name' => $title,
'link' => $uri,
'description' => $desc,
'picture'=>$pic,
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/me/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);


?>

I get the access token successfully, so only these 2 parameters are what I need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文