如何使用Facebook的PHP SDK v4和图形API 2.x到发布在Facebook页面壁管理员岗位 [英] how to publish post on facebook page wall as admin using facebook php sdk v4 and graph api 2.x

查看:247
本文介绍了如何使用Facebook的PHP SDK v4和图形API 2.x到发布在Facebook页面壁管理员岗位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Facebook的PHP SDK v4和图形API 2.x到发布的Facebook页面壁页管理员用户交?

how to publish post on Facebook page wall as page admin user using facebook php sdk v4 and graph api 2.x?

我花了很多时间,但大部分文章都是旧(旧Facebook的PHP SDK中的例子),并有点混乱

I have spent lot of hours but mostly articles are old(examples with old Facebook PHP SDK) and bit confusing

我已经想通了,下面的步骤

I have figured out following steps

第1步:应用重定向至Facebook的日志管理结果
第2步:获取用户访问令牌(短期)结果
第3步:通过交换短暂的令牌结果获得用户的访问令牌(长住)
第4步:获取页面访问令牌

你能解释一下,请我需要调用以上步骤,Facebook的PHP SDK功能
或者你可以给我一些code例子网址是什么?

Can you explain please which functions of Facebook PHP SDK I need to call for above steps or you can give me url of some code example?

如果我错了,那么请大家指正
感谢提前

If I am wrong then please correct me Thanks for advance

=======================结果
注:

=======================
Note:


  • 我创建应用APP_ID和app_secret

  • 我创建Facebook页面

  • 我使用Facebook的PHP SDK 4

  • Facebook的PHP SDK 4使用图形API 2.x的(我认为)

推荐答案

我有一个<一个href=\"https://www.webniraj.com/2014/08/23/facebook-api-posting-as-a-page-using-graph-api-v2-x-and-php-sdk-4-0-x/\"相对=nofollow>教程,说明如何实现使用PHP SDK v4.0.x和图形API V.X发布到页面。

I have a tutorial that explains how to achieve posting to a page using the PHP SDK v4.0.x and Graph API v.x.

从本质上讲,你可以通过执行以下操作遇到页面访问令牌:

Essentially, you can get a Page Access Token by doing the following:

// get page access token
$access_token = (new FacebookRequest( $session, 'GET', '/' . $page_id,  array( 'fields' => 'access_token' ) ))
    ->execute()->getGraphObject()->asArray();

// save access token in variable for later use  
$access_token = $access_token['access_token'];

然后就可以进行第二次的API调用使用我们上面获得访问令牌才能发布到指定网页:

Then you can make a second API call to post something to a given page using the access token we obtained above:

// post to page
$page_post = (new FacebookRequest( $session, 'POST', '/'. $page_id .'/feed', array(
    'access_token' => $access_token,
    'name' => 'Facebook API: Posting As A Page using Graph API v2.x and PHP SDK 4.0.x',
    'link' => 'https://www.webniraj.com/2014/08/23/facebook-api-posting-as-a-page-using-graph-api-v2-x-and-php-sdk-4-0-x/',
    'caption' => 'The Facebook API lets you post to Pages you administrate via the API. This tutorial shows you how to achieve this using the Facebook PHP SDK v4.0.x and Graph API 2.x.',
    'message' => 'Check out my new blog post!',
  ) ))->execute()->getGraphObject()->asArray();

// return post_id
print_r( $page_post );

这篇关于如何使用Facebook的PHP SDK v4和图形API 2.x到发布在Facebook页面壁管理员岗位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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