[英]Facebook API daily post from PHP/MySQL
I'm working on a problem for many days now without solution. 我现在正在研究一个问题很多天没有解决方案。
What I got : 我得到了什么:
What I'm looking for : 我在找什么:
The best result I got so far : 到目前为止我得到的最好结果:
Is it possible to save the login informations in the PHP script to get a fully automatic daily post with cron ? 是否可以在PHP脚本中保存登录信息以获得cron的全自动日常帖子?
Does anyone know a solution ? 有谁知道解决方案?
Sincerly, 诚恳,
Ok folks, I did it . 好的伙计们, 我做到了 。
Here is my solution : 这是我的解决方案:
1) Download the Facebook PHP SDK from https://github.com/facebook/facebook-php-sdk 1)从https://github.com/facebook/facebook-php-sdk下载Facebook PHP SDK
2) Generate an extended access token with this code (generate_token.php) : 2)使用此代码生成扩展访问令牌(generate_token.php):
require_once('src/facebook.php'); $facebook = new Facebook(array( 'appId' => 'YOUR APP ID', 'secret' => 'YOUR APP SECRET ID', 'fileUpload' => true )); $facebook->setExtendedAccessToken(); $access_token = $_SESSION["fb_".$fb_appId."_access_token"]; $facebook->setAccessToken($access_token); $accessToken = $facebook->getAccessToken();
The $accessToken is a 60 days long access to your account by the application. $ accessToken是应用程序对您帐户的60天访问权限。
Store this token in your database. 将此令牌存储在数据库中。
3) Publish script (fb_post.php): 3)发布脚本(fb_post.php):
Get the $accessToken from your database, then use it to access to your account without manuel login : 从您的数据库获取$ accessToken,然后使用它来访问您的帐户而无需manuel登录:
require_once('src/facebook.php');
$app_id = 'YOUR APP ID'; $app_secret = 'YOUR APP SECRET ID'; $config = array( 'appId' => $app_id, 'secret' => $app_secret, ); $facebook = new Facebook($config); $facebook->setAccessToken($fbAccessToken); $user_id = $facebook->getUser();
Use the first page (generate_token.php) once every 2 months to generate a 60 days token. 每2个月使用第一页(generate_token.php)生成60天令牌。
"Et voila", just configure a daily Cron Job which execute "fb_post.php" and your robotic Facebook will rise ! “Et voila”,只需配置一个执行“fb_post.php”的日常Cron作业,你的机器人Facebook就会上升!
did you try facebook SDK for PHP, it is simple you have to register your app with facebook and use your application id and application secret following link contains a sample script. 你试过PHP的facebook SDK,很简单,你必须在Facebook注册你的应用程序,并使用你的应用程序ID和应用程序密码链接包含一个示例脚本。
developers.facebook.com/docs/php/howto/postwithgraphapi developers.facebook.com/docs/php/howto/postwithgraphapi
1.You need your Website to set as an Facebook App 1.您需要将您的网站设置为Facebook应用程序
2.read into https://developers.facebook.com/docs/opengraph/ 2.阅读https://developers.facebook.com/docs/opengraph/
Basicly it is possible of course. 基本上它当然是可能的。 But it for me it needs time to get used to the Graph Api. 但对我来说,需要时间来适应Graph Api。
means a quick answer for your desire is not possible 意味着无法快速回答您的愿望
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.