如何以编程方式发布到您自己的Facebook页面? [英] How to post programatically to your own facebook page?

查看:70
本文介绍了如何以编程方式发布到您自己的Facebook页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况如下. 我是一个Facebook应用程序和一个Facebook页面的所有者.我想以编程方式(从代码)发布到此Facebook页面. 据我所知,我需要一个Facebook应用程序来做,所以我创建了一个. 我正在使用facebook php sdk和代码点火器.(我没有使用javascript sdk).

My situation is the following. I am the owner of a facebook app,and a facebook page.I would like to programatically(from code) post to this facebook page. As far as I know I need a facebook app to do that so I created one. I am using the facebook php sdk and code igniter.(I am not using the javascript sdk).

我有facebook对象.我登录到Facebook时,打印了它的方法并尝试使用printint作为用户ID. 这没有用. 我的问题如下: 1)为什么不能打印Facebook ID? 2)以编程方式发布到我的Facebook页面上最简单的解决方案是什么?(从我的应用程序还是从用户)

I have the facebook object.I printed it's methods and tried printint the user id while I was logged into facebook. This did not work. My questions are the following: 1)Why does it not work to print the facebook id? 2)What is the most simplest solution to programatically post to my facebook page ?(from my app,or from my user)

我在做什么错? 这是我的代码

What am I doing wrong ? This is my code

$config = array(
  'appId'  => 'xxxx',
  'secret' => 'xxxx',
  'cookie' => true,
);


$this->load->library('facebook', $config);
echo '<pre>';print_r(get_class_methods($this->facebook));

 $id = $this->facebook->getAppId();
 $secret =$this->facebook->getApiSecret();
 $uri = "http://tipsterscorner.com/stats/display/facebook1";//callback_url se pare ca nu e bun

///我建立了facebook的URL.如果我在浏览器中使用它,我会得到一系列的弹出窗口(你允许应用程序blabla) //我在某处读到,如果将最后一个参数更改为code并使用curl,我将在响应中获得令牌 //显示在返回网址的屏幕上,但这不会发生

//i build the facebook url.If I use this in the browser ,I get a series of popups(do you allow the application to blabla) //I read somewhere that if I change the last parametere to code,and use curl,I will get the token in the response //printed on the screen of the return url,but that does not happen

 $facebook_url = "https://www.facebook.com/dialog/oauth?`client_id=$id&client_secret=$secret&redirect_uri=$uri&scope=publish_stream,offline_access,read_stream,manage_pages&response_type=token";`


$curl = curl_init();
// Set some options - we are passing in a useragent too here
    curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $facebook_url,
    CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);

这是网址. http://tipsterscorner.com/stats/display/facebook1

非常感谢您.

推荐答案

要独自(或代表他人使用该应用程序)在Facebook上发布,您需要获取user access令牌. Access Tokens有两种,即App Access TokenUser Access Token.当应用代表用户发布时,User Access Token是必需的.当用户授予该应用程序权限时,将生成User Access Token(您在浏览器中输入Facebook URL时遇到的对话框弹出窗口).是否授予应用代表其发布的权限完全由用户决定.应开发App以处理这两种情况.一旦用户授予许可(Basic Permission,其中包括该用户的所有公共可用信息),将生成用户访问令牌.您可以将其存储在database tableSESSION中.
有时用户访问令牌可能变得无效,因此必须检索新令牌.在这段时间内,可以使用curl进行检索,因为用户已经授予了该应用程序的权限.
http://developers .facebook.com/blog/post/2011/05/13/how-to--handle-expired-access-tokens/

To post on facebook by yourself and on behalf of other's using the app you need to obtain user access token. There are two kinds of Access Tokens namely App Access Token and User Access Token. When app is posting on user's behalf User Access Token is required. User Access Token is generated when a User gives permissions for the app(The dialog popup which you experienced when entering the facebook url in browser). Its solely upon user whether or not to grant permission to the app to post on their behalf. App should be developed to handle both the situations. Once User have given permission(Basic Permission which includes all publicly available info of the user), user access token will be generated. You can either store it in database table or in SESSION.
Sometimes user access tokens may become invalid and new token has to be retrieved. During that time curl can be used to retrieve because user has already granted permission for the app.
http://developers.facebook.com/blog/post/2011/05/13/how-to--handle-expired-access-tokens/

这篇关于如何以编程方式发布到您自己的Facebook页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆