与Facebook Graph API有关的问题 [英] Issue related to Facebook Graph API

查看:111
本文介绍了与Facebook Graph API有关的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Facebook :: $ CURL_OPTS [CURLOPT_SSL_VERIFYPEER] = false ; 
Facebook :: $ CURL_OPTS [CURLOPT_SSL_VERIFYHOST] = 2;

$ facebook = new Facebook(array('appId'=>'xxxxxxxxxxx','secret'=>'xxxxxxxxxxx .... xxxxxxx','scope'=>'manage_pages, offline_access,publish_stream,user_photos'));
$ result = $ facebook-> api('/'.$ rssfeed_id,'get');

上面的代码给了一些错误喜欢: -

 致命错误:未捕获OAuthException:(#15)需要在从C:\Program Files \EasyPHP-5.3.5.0\www\sportsflow中抛出的桌面应用程序调用时进行会话\sportsflow_v30\lib\base_facebook.php在线1271 

请给我上面的任何解决方案定义问题。

解决方案

您需要一个用户连接才能给他权限。



Facebook()构造函数只需要一个应用程序ID和一个键:



<$ p $ (
'appId'=>'xxxxxxxxxxx',
'secret'=>'xxxxxxxxxxx .... xxxxxxx')) ;

权限应添加到LoginUrl:

  $ loginurl = $ facebook-> getLoginUrl(array(
'scope'=>'manage_pages,offline_access,publish_stream,user_photos'));

用户点击登录URL后,您可以使用$ facebook实例来获取用户会话:

  $ user = $ facebook-> getUser(); 

如果用户确实存在,最终可以提出您想要的API请求:

  $ result = $ facebook-> api('/'.$ rssfeed_id,'get'); 

按照这个完整的例子: https://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php


Acctually I am using that code for getting the facebook post data.

Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;

$facebook = new Facebook(array('appId'  => 'xxxxxxxxxxx', 'secret' => 'xxxxxxxxxxx....xxxxxxx', 'scope'  => 'manage_pages,offline_access,publish_stream,user_photos'));
$result = $facebook->api('/'.$rssfeed_id,'get');

Above code gave some error Like:-

 Fatal error: Uncaught OAuthException: (#15) Requires session when calling from a desktop app thrown in C:\Program Files\EasyPHP-5.3.5.0\www\sportsflow\sportsflow_v30\lib\base_facebook.php on line 1271

Please give me any solution for above define problem.

解决方案

You need a user to connect in order to give him the permissions.

The Facebook() constructor only takes an app ID and a key:

$facebook = new Facebook(array(
                     'appId'  => 'xxxxxxxxxxx', 
                     'secret' => 'xxxxxxxxxxx....xxxxxxx'));

The permissions should be added to the LoginUrl:

$loginurl = $facebook->getLoginUrl(array(
        'scope'  => 'manage_pages,offline_access,publish_stream,user_photos'));

Once the user clicked on the login URL, you can then use the $facebook instance to get the user session:

$user = $facebook->getUser();

If the user indeed exists, you can finally make the API request you want:

$result = $facebook->api('/'.$rssfeed_id, 'get');

Follow this complete example: https://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php

这篇关于与Facebook Graph API有关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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