Facebook创建应用程序页面上传照片到页面的相册 [英] facebook create app for page to upload photos to page's photo album

查看:114
本文介绍了Facebook创建应用程序页面上传照片到页面的相册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Facebook应用程序开发完全陌生,所以请与我保持联系。

I'm completely new to Facebook app development, so please bear with me.

我被要求创建一个Facebook页面,一个应用程序将让用户将照片上传到其中一张专辑中。

I've been asked to create a Facebook Page, with an application that will let users upload photos into one of the Page's albums.

我设法创建了页面,让我们称之为 MyPage 。我还创建了一个应用程序 MyApp ,我已将该应用程序添加到该页面的配置文件。现在,当您在左侧(标签)中查看 MyPage 配置文件时,您将已经找到 MyApp

I've managed to create the page, let's call it MyPage. I've also created an app MyApp, and I've added the App to the profile of the Page. Now, when you view MyPage profile, on the left (tabs), you will already find MyApp.

MyApp 指向我的主机帐户的php页面。它有一个带有文件字段的表单:

MyApp points to a php page on my hosting account. It has a form with a file field:

<form action="<?=$PHP_SELF;?>" enctype="multipart/form-data" method="post">
    <input name="MAX_FILE_SIZE" type="hidden" value="10000000" />
    <input id="fileSelect" name="fileSelect" type="file" />
    <input name="submit" type="submit" value="Upload" />
</form>

和以下代码来处理上传的文件,并据说放入 MyPage 的相册

and the following code to handle the uploaded file and supposedly put into MyPage's album:

if(count($_FILES)){
    $name = ereg_replace(' ', '_', basename($_FILES['fileSelect']['name'])); 
    $uploadFile = "uploads/" . $name; 
    if (move_uploaded_file($_FILES['fileSelect']['tmp_name'], $uploadFile)) { 
    $facebook->setFileUploadSupport(true);

    $args = array('message' => 'Photo Caption');
    $args['image'] = '@' . realpath($uploadFile);

    $data = $facebook->api('/THE_ALBUM_ID/photos', 'post', $args);

    //get rid of the original on the main server 
    unlink($uploadFile);
    }
}

但是,当提交上传按钮时,我收到这个错误,就在 MyPage 的iframe为 MyApp

However, when the "Upload" button is submitted, I get this error, right in MyPage's iframe for MyApp:

Fatal error: Uncaught OAuthException: (#120) Invalid album id thrown in /COMPLETE_PATH/facebook-php-sdk/src/base_facebook.php on line 1033

graph.facebook.com/THE_ALBUM_ID

Even tho the album id is really correct, and displays when I use Graph API Explorer, or graph.facebook.com/THE_ALBUM_ID

顺便说一句,我把它放在脚本的顶部:

By the way, I put this on top of the script:

require 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'THE_APP_ID',
  'secret' => 'THE_APP_SECRET',
));

我缺少什么?任何帮助将不胜感激。

What am I missing? Any help would be much appreciated.

推荐答案

我发现通过Facebook API将照片上传到页面的唯一方法是做作为页面。为了做到这一点,您需要先进行身份验证。为此,您必须:

The only way I found to upload photos to a page through the Facebook API is doing it AS the Page. In order to do that you need to authenticate as the page first. To do that you have to:


  1. 使用 manage_pages 许可。

  2. 使用

  1. Authenticate with the user who owns the page with the manage_pages permission.
  2. Request the pages with

/ me / accounts?access_token = YOUR_ACCESS_TOKEN

找到相应页面的 access_token p>

  • 使用 access_token 上传照片。

  • Find the access_token of the corresponding page.

    如果您需要USERS将照片上传到页面,您可以向拥有该页面的用户获取一个长命令,并将其存储以使用该令牌,而不是用户令牌上传照片。上传的照片不会以用户身份上传,但会出现在页面上传。

    If you need USERS to upload photos to the page you could get a long lived token with the user who owns the page and store it to use that token instead of users tokens to upload photos. The uploaded photo won't appear uploaded as the user though, it will appear uploaded by the page.

    这篇关于Facebook创建应用程序页面上传照片到页面的相册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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