简体   繁体   English

使用Facebook Graph API(Javascript)从页面的照片中获取图像的URL

[英]Get image's URL from page's photos using Facebook Graph API (Javascript)

I have followed several tutorials but it seems the newest version of the Graph API broke many of them. 我遵循了一些教程,但是最新版本的Graph API似乎打破了许多教程。

Here's my code: 这是我的代码:

function getAlbumImages(){
    FB.api(        
        '/760126260690750/photos',
        'GET',
        {"limit":"100",
        "access_token":"833367813443301|nDhKBT0o6K7a7j_5LMfc3QSbRNs"},
        function (response) {
           if (response && !response.error) {
               createGallery(response);
            } else
                console.log(response.error);
    });
}

function createGallery(imageJSON) {
    for (var i=0, length = imageJSON.data.length; i < length; i++){
        var image = imageJSON.data[i];
        $('body').append(image.name);
    }
};

However, nothing is appended to the body. 但是,没有任何东西附加到身体上。 Upon further inspection of the API call, the method /albumid/photos returns a photo object as specified by the docs, but this object does not contain anything but the ID, title and date of the photo. 进一步检查API调用后,方法/ albumid / photos返回文档指定的照片对象,但是该对象除照片的ID,标题和日期外不包含其他任何内容。 This is an excerpt of the data returned by my query: 这是我的查询返回的数据的摘录:

{
"data": [
{
  "created_time": "2015-07-23T21:39:40+0000",
  "name": "summer is here!! #adisfrutar #relax #funnytime 💘😊🌴☀🐙🎼",
  "id": "903479883022053"
},

So clearly, the new API call does not return the image URL as it used to. 显然,新的API调用不会返回图像URL。

My question is then, how do I get the image URLs from the page's album so I can display a gallery on my website? 我的问题是,如何从页面相册中获取图像URL,以便可以在我的网站上显示图库?

You need to add the image field to the url (fields=images). 您需要将图像字段添加到url(fields = images)。 Example: 例:

https://graph.facebook.com/v2.4/760126260690750/photos?access_token=833367813443301%7CnDhKBT0o6K7a7j_5LMfc3QSbRNs&fields=images,name,created_time https://graph.facebook.com/v2.4/760126260690750/photos?access_token=833367813443301%7CnDhKBT0o6K7a7j_5LMfc3QSbRNs&fields=images,name,created_time

EDIT: If you need additional information about the photo node, check the Graph Api: 编辑:如果您需要有关照片节点的其他信息,请检查Graph Api:

https://developers.facebook.com/docs/graph-api/reference/photo https://developers.facebook.com/docs/graph-api/reference/photo

You can see all possible parameters under the GET request. 您可以在GET请求下查看所有可能的参数。

暂无
暂无

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

相关问题 如何使用图形API从用户的Facebook新闻源中仅获取照片? - How to get only photos from user's Facebook newsfeed using graph api? 您是否可以使用Graph API获取公共Facebook页面的订阅源而无需要求用户允许? - Can you get a public Facebook page's feed using Graph API without asking a user to allow? JavaScript:如何使用API​​ Graph喜欢Facebook墙上的帖子(给定Facebook页面URL和Facebook帖子ID)? - JavaScript: How to like a Facebook wall post (given a Facebook page URL and a Facebook post id) using API Graph? 使用Facebook Graph API获取用户朋友的列表 - Using the Facebook Graph API to get a list of a user's friends 从 Facebook 页面获取最新帖子,并仅使用新的 Graph API JavaScript 显示在网站上 - Get most recent post from Facebook page, and display on website using new Graph API JavaScript only 我可以使用Facebook Graph API从活动的提要中获取所有帖子吗? - Can i get all posts from an event's feed using Facebook Graph API? 使用 Javascript 和 Facebook 图 API 的可点击图像 - Clickable image using Javascript and Facebook graph API 使用JavaScript SDK从Facebook图形API获取个人资料图片 - Get profile picture from facebook graph api using javascript SDK 在JavaScript中使用Facebook API获取测试用户的照片 - Get photos of Test User using Facebook API in javascript 使用Javascript SDK Graph API获取用户的新闻提要 - Get User's News Feed Using Javascript SDK Graph API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM