将图像上传到特定的Facebook相册

时间:2012-02-13 12:22:49

标签: php facebook facebook-graph-api

我无法使用权​​限上传到特定的Facebook相册。

我被设置为特定Facebook页面的管理员,但每当我尝试上传照片时,我似乎都无法访问它。

我得到的错误是:

  

致命错误:未捕获OAuthException:(#120)抛出无效的专辑ID

如果我使用Graph explorer进行探索,我可以看到这张专辑没有任何访问令牌。

我使用的网址是https://graph.facebook.com/albumId/photos

我试图上传的专辑是Facebook页面中的一张专辑,我在Facebook中创建了这张专辑。

我设置的权限是:

  • user_photos
  • friends_photos
  • publish_actions
  • manage_pages
  • publish_stream
  • photo_upload

任何帮助表示感谢。

3 个答案:

答案 0 :(得分:1)

首先,检查用户是否已登录:

function getLoginStatus() {  
            FB.getLoginStatus(function (response) {
                if (response.status === 'connected') {
                    // the user is logged in and connected to your
                    // app, and response.authResponse supplies
                    // the user's ID, a valid access token, a signed
                    // request, and the time the access token 
                    // and signed request each expire
                    var uid = response.authResponse.userID;
                    var accessToken = response.authResponse.accessToken;

                    getPageAccess();

                } else if (response.status === 'not_authorized') {
                    // the user is logged in to Facebook, 
                    //but not connected to the app
                    logIn();
                } else {
                    // the user isn't even logged in to Facebook.
                    logIn();
                }
            });
        }

然后获取与用户关联的页面访问令牌:

function getPageAccess() {               
            FB.api('/PAGE_ID?fields=access_token', function (resp) {
                var pageAccessToken = resp.access_token;
            });
        }

答案 1 :(得分:1)

这似乎是一个常见问题。如果您想冒充Facebook页面(即,作为页面本身进行上传,发布和共享),您必须首先获取该页面的访问令牌:

  1. 使用用户访问令牌向
  2. 循环结果集并查找页面(注意到每个项目的类别属性,跳过“应用程序”,因为它被视为帐户)
  3. 为该页面存储access token
  4. 然后(使用PHP SDK):

    $page    = '432652662'; // Your page id
    $album   = '128949205'; // Your album id
    $source  = 'mypic.png'; 
    $payload = array('source' => '@' . $source,
        'access_token' => 'page access token');
    
    // Upload photo for specific page and album
    $sdk->api("/$page/$album/photos", 'POST', $payload);
    

答案 2 :(得分:0)

好的,我想我找到了解决方案。

如果你转到https://graph.facebook.com/me/accounts

每个帐户都有自己的access_token。将图像上传到Facebook页面时,您需要将该access_token作为参数传递。

相关问题