1

我正在尝试为客户提供 Facebook 画廊,并且由于该站点托管在服务器上,因此需要对请求进行身份验证。

我已经使用我们公司的 Facebook 开发者帐户设置了一个应用程序。虽然我已将应用程序的域设置为我们客户的域,但请求中返回的图库是空的。

我假设我需要访问客户的 facebook 帐户,以便我可以创建一个与他们的 facebook 帐户直接关联的应用程序 - 我想要画廊的那个?编辑 - 只是想我会指出客户不想给我他们的 Facebook 帐户的密码......

这是我使用的身份验证代码,如果有人愿意指出我可能犯的任何男生错误。

$no_albums = 6;
$latest_albums = null;

$user_id = "xxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxx";
$app_token_url = "https://graph.facebook.com/oauth/access_token?"
                        . "client_id=" . $user_id
                        . "&client_secret=" . $app_secret 
                        . "&grant_type=client_credentials"
                    . "&scope=user_photos";

$response = wp_remote_get($app_token_url);
$access_token = $response['body'];
error_log(print_r($response,true));

$query = 'https://graph.facebook.com/'.$user_id.'/albums?' . $access_token;
$albums = json_decode(file_get_contents('http://graph.facebook.com/'.$user_id.'/albums') );

这是我在错误日志中得到的响应( $albums ):

Array
(
    [headers] => Array
        (
            [access-control-allow-origin] => *
            [cache-control] => private, no-cache, no-store, must-revalidate
            [content-type] => application/json; charset=UTF-8
            [etag] => "1050253aec7b29caff644806927dabfa81406eee"
            [expires] => Sat, 01 Jan 2000 00:00:00 GMT
            [pragma] => no-cache
            [x-fb-rev] => 812093
            [x-fb-debug] => 9I0lRzV3GZxrflP/19iBvhly6FLUVI9jCHJAXcw0Dm0=
            [date] => Mon, 13 May 2013 10:45:39 GMT
            [connection] => close
            [content-length] => 11
        )

    [body] => {"data":[]}
    [response] => Array
        (
            [code] => 200
            [message] => OK
        )

    [cookies] => Array
        (
        )

    [filename] => 

谢谢。

4

1 回答 1

0

这里有几个基本问​​题。

首先,在您的 API 请求中,您正在寻找与您的APP_ID. 没有了。您应该使用客户端的PAGE_IDUSER_ID在对图形 API 的请求中。

其次,您应该使用 Facebook PHP SDK而不是file_get_contents()发出请求。特别是如果这是一个生产环境。

如果您的客户相册是公开可见的,您可能不需要对用户进行身份验证即可查看它们。要确定这一点,您需要分享您客户的 Facebook 用户名。

于 2013-05-13T12:52:12.157 回答