将图像发布到预定义页面上的相册

发布于 2025-01-08 20:49:51 字数 869 浏览 0 评论 0原文

我试图让用户将我网站上的图像发布到特定 Facebook 页面上的相册中。 在他能够在计算机上选择图像之前,他需要登录 facebook,并且必须向我们的应用程序授予所需的权限(随意流程)

为了将所选图像发布到我们页面的相册,我们需要一个访问令牌,因此我们拥有执行此操作的正确权限。 我们可以通过执行以下步骤手动获取权限:

  1. 导航到以页面管理员身份登录的以下网址,并授予权限(user_photos、manage_pages、offline_access、publish_stream)

    https://www.facebook.com/dialog/oauth?
    client_id=;
    &redirect_uri=;
    &response_type=令牌
    &范围=用户照片、管理页面、离线访问、发布流
    
  2. 当您向应用程序授予所需权限时,您将获得例如,重定向到 canvas_url#access_token=*access_token*

    http://example.com/#access_token=awe12
    
  3. 然后导航到

    https://graph.facebook.com/me/accounts?access_token=#access_token
    (使用 2 中的访问令牌)。 
    

    这将列出您管理的页面;记下您要将图像上传到的页面的 access_token

现在,有没有办法自动执行此操作? 或者更好的是,有没有办法为此页面生成永不过期的访问令牌?

I'm trying to let a user post an image on my website to an album on a specific facebook-page.
Before he's able to select an image on his computer he needs to be logged in at facebook and must have given the needed rights to our application (casual flow)

For posting the selected image to the album of our page we need an access token so we have the right permissions to do this.
We can get the permissions by hand by doing the following steps:

  1. Navigate to the url below logged in as the admin of the page, and give the permissions (user_photos,manage_pages,offline_access,publish_stream)

    https://www.facebook.com/dialog/oauth?
    client_id=<application_id>
    &redirect_uri=<canvas_url>
    &response_type=token
    &scope=user_photos,manage_pages,offline_access,publish_stream
    
  2. When you give the application the required permissions you'll be redirected to canvas_url#access_token=*access_token*, for example

    http://example.com/#access_token=awe12
    
  3. Then navigate to

    https://graph.facebook.com/me/accounts?access_token=#access_token
    (using the access token from 2). 
    

    This will list the pages you administer; write down the access_token for the page(s) to which you want to upload the image

Now, is there a way to do this automagically?
Or better, is there a way to generate an access-token for this page, that will never expire?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇到 2025-01-15 20:49:51

您不必使用页面的 access_token 即可发布到页面相册。如果您使用页面的 access_token,则图像将显示为好像是由页面发送的(而不是由用户发送的)。

只要相册具有公共访问权限(意味着任何人都可以将照片上传到该页面的相册)。您所需要做的就是要求用户授予您 publish_stream 权限并使用他的 access_token 上传图像。

如果您使用 PHP Sdk 执行此操作,它应该如下所示:

  $facebook->api("ALBUM_ID/photos","POST",array(
        "message"=>"some message",
        "source"=>"@PATH_TO_IMAGE"
  ));

当然,您需要在 $facebook 对象中启用 imageUpload,并向脚本传递 signed_request 或设置 access_token 以便 SDK 使用当前用户的 access_token。

You don't have to use the page's access_token in order to post to the page album. If you use the page's access_token then the image will be shown as if it was sent by the page (and not by the user).

As long as the album has public access (means that anyone can upload photos to the page's albums) . All you need is to ask the user to grant you publish_stream permission and upload the image with his access_token.

If you're doing it with the PHP Sdk it should look something like this:

  $facebook->api("ALBUM_ID/photos","POST",array(
        "message"=>"some message",
        "source"=>"@PATH_TO_IMAGE"
  ));

Of course you will need to enable imageUpload in the $facebook object, and pass the script the signed_request or set the access_token in order for the SDK to use the current user's access_token.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文