如何通过一次调用Facebook Graph API获取多个专辑图片网址

时间:2016-02-03 00:05:58

标签: javascript facebook facebook-graph-api

我可以传递字符串" album.id/photos"我得到一个如下所示的列表,我在相册中有每个照片ID,但它不会返回每张图片的URL(只是id)。我是否必须为我想要获取网址的每张图片运行一次调用,或者是否有办法通过下面的调用返回网址?



NSString




以下是我在Javascript中调用的内容



{
  "data": [{
    "created_time": "2011-01-21T20:19:49+0000",
    "id": "10150091489547705"
  }, {
    "created_time": "2010-02-03T03:31:56+0000",
    "id": "293935837704"
  }, {
    "created_time": "2009-01-02T02:46:28+0000",
    "id": "56480657704"
  }],
  "paging": {
    "cursors": {
      "before": "MTAxNTAwOTE0ODk1NDc3MDUZD",
      "after": "NTY0ODA2NTc3MDQZD"
    }
  }
}




1 个答案:

答案 0 :(得分:0)

无需为每个图片ID运行单个请求。

在api请求的字段中添加来源,这会返回每张图片的源网址以及ID。

例如:/ {album_id} / photos?fields = source,created_time

返回输出,如:

    var clientd = new ClientD()
        {
            client_id = client_id,
            redirect_uri = redirect_uri,
            client_secret = client_secret,
            code = code,
            grant_type = grant_type
        };


    String url = "https://accounts.google.com/o/oauth2/token";
            using (var client = new System.Net.Http.HttpClient())
            {
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add
                (new MediaTypeWithQualityHeaderValue("application/json"));
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(clientd);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var httpResponseMessage = await client.PostAsync(url, content);
                if (httpResponseMessage.StatusCode == HttpStatusCode.OK)
                {
                    return httpResponseMessage.StatusCode.ToString();
                }
                else
                {
                    return httpResponseMessage.StatusCode.ToString();
                }
            }

希望这会有所帮助:)