如何使用具有自动装载机的作曲家的Facebook SDK 4.0 [英] How to use Facebook SDK 4.0 without composer with autoloader

查看:137
本文介绍了如何使用具有自动装载机的作曲家的Facebook SDK 4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向Facebook用户发送通知。



我有以下设置示例,但似乎无法到达任何地方,Keeps发出错误Facebook Class not found。

 <?php 
session_start();
require_once'autoload.php';
require_once('src / Facebook / FacebookSession.php');
require_once('src / Facebook / FacebookRequest.php');

使用Facebook\FacebookSession;
使用Facebook\FacebookRequest;
$ facebook = new Facebook();

$ app_id ='654346742464654654';

$ app_secret ='--my-secret--';

$ app_access_token = $ app_id。 '|'。 $ app_secret;

$ response = $ facebook-> api('/ 65785757987982452465465445465 / notifications','POST',array(

'template'=>'你收到新消息',

'href'=>'相对URL',

'access_token'=> $ app_access_token
));

print_r($ response);
?>

谢谢。

解决方案

您需要对Facebook API执行基本请求的关键类是 FacebookSession FacebookRequest 。以下示例尝试在用户的墙上发布。

  //首先,使用您的Facebook应用程序ID和密码初始化

FacebookSession :: setDefaultApplication(YOUR_APP_ID,YOUR_APP_SECRET);

//现在它创建一个新的FacebookSession实例的时间

$ session = new FacebookSession($ accessToken);

//发送API请求发布
$ response =(新的FacebookRequest($ session,POST,/ me / feed,array(
message =>我很酷的人
))) - > execute();

$ responseObject = $ response-> getGraphObject();

//做一些结果

此外,你必须确保您的Facebook应用程序有足够的权限执行您要求的操作(在此情况下发送通知)



有关Facebook API权限审查的更多详细信息,请查看:
https://developers.facebook.com/docs/apps/review



有关Facebook PHP Api的详细信息:
https://developers.facebook.com/docs/reference/php/4.0.0



希望它有帮助


I want to send a notification to a Facebook user.

I have the following setup example, but can't seem to get anywhere, Keeps giving an error that "Facebook Class not found".

<?php 
session_start();
require_once 'autoload.php';
require_once( 'src/Facebook/FacebookSession.php' );
require_once( 'src/Facebook/FacebookRequest.php' );

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
$facebook = new Facebook();

$app_id = '654346742464654654';

$app_secret = '--my-secret--';

$app_access_token = $app_id . '|' . $app_secret;

$response = $facebook->api( '/65785757987982452465465445465/notifications', 'POST', array(

                'template' => 'You have received a new message.',

                'href' => 'RELATIVE URL',

                'access_token' => $app_access_token
            ) );    

print_r($response);
?>

Thanks.

解决方案

The key classes you need to do basic requests to Facebook API are FacebookSession and FacebookRequest. The following example tries to post at user's wall.

//First of all, initialize with your Facebook App id and secret

FacebookSession::setDefaultApplication("YOUR_APP_ID", "YOUR_APP_SECRET");

//Now its time to make a new FacebookSession instance

$session = new FacebookSession($accessToken);

//Sending the API request for posting
$response = (new FacebookRequest($session,"POST","/me/feed",array(
                "message" => "I'm a cool guy"
            )))->execute();

$responseObject = $response->getGraphObject();

//do something with the result

Additionally you have to make sure your Facebook application has enough permissions to do the action you are requesting (send a notification in this case)

For further details about Facebook API permissions review please check: https://developers.facebook.com/docs/apps/review

And for details about Facebook PHP Api: https://developers.facebook.com/docs/reference/php/4.0.0

Hope it helps

这篇关于如何使用具有自动装载机的作曲家的Facebook SDK 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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