简体   繁体   English

PHP Facebook SDK-如何获取特定用户的照片

[英]PHP Facebook SDK - How to get specific user's photos

I need to pull a client's Facebook profile pictures (by album name) and print their photos on their website. 我需要拉出客户的Facebook个人资料照片(按相册名称),然后在他们的网站上打印他们的照片。

<?php
    $result = $facebook->api('/****/albums', array('access_token' => $facebook->access_token, 'name' => $album));
?>

This is throwing the following error: 这将引发以下错误:

Fatal error: Uncaught OAuthException: A user access token is required to request this resource. thrown in .../includes/fb/base_facebook.php on line 1028

We have set his albums as public, and still no dice. 我们已经将他的专辑设为公开,但仍然没有骰子。 Is this possible, or do we have to set up a Facebook Page (we don't want to do this because he needs to upload photos via his phone). 这是否可行,还是我们必须建立一个Facebook Page(我们不想这样做,因为他需要通过手机上传照片)。

For getting access to a user's album you first need to get the 'req_perms' => 'publish_stream,user_photos,read_stream' by the user. 为了获得对用户相册的访问权,您首先需要获得用户的'req_perms'=>'publish_stream,user_photos,read_stream' It will allow you to get access to the album pics of user. 它将允许您访问用户的相册图片。

Then, use $facebook->api('/me/albums') for getting all the albums then use $facebook->api("/{$album_id}/photos") for obtaining all the photos within a given album. 然后,使用$ facebook-> api('/ me / albums')获取所有相册,然后使用$ facebook-> api(“ / {$ album_id} / photos”)获取给定相册中的所有照片。

Only making the album as public don't mean that it can be accessed without permission you always need the user's permission to access his any kind of data (either public or private). 仅将相册设为公开并不意味着未经允许就可以对其进行访问,您始终需要用户的许可才能访问其任何类型的数据(公开或私有)。

Not sure but seems your access token has problem, try: 不确定,但似乎您的访问令牌有问题,请尝试:

$facebook->getAccessToken(); // instead of $facebook->access_token

Hope it works for you 希望这对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM