facebook - 如何使用 Facebook API 在 1 个请求中获取多个头像
问题描述
我开发了一种方法来获取(执行 http 请求)我朋友的 facebook 头像并将每个图像转换为 Sprite。如果我有 5 个朋友,我会提出 5 个请求。几个月前它起作用了。但现在它不起作用。当我尝试获取第二个头像时,我收到“超时”响应。
我想这个问题与我正在做的请求数量有关。也许 Facebook 有一个新的“防洪”。
所以,现在,我正在尝试只发出一个 http 请求来同时获取所有头像。在官方文档(https://developers.facebook.com/docs/graph-api/making-multiple-requests)中,我读到我应该使用“批量请求”,但我得到的响应不包含构建每个图像的信息。我该如何解决?
背景:C++/cocos2d-x/class network::HttpRequest
network::HttpRequest* req = new network::HttpRequest();
req->setUrl("https://graph.facebook.com");
vector<string> header;
header.emplace_back("User-Agent: MyApp/1.0");
header.emplace_back("Content-Type: application/json");
req->setHeaders(header);
req->setRequestData(requestBody.c_str(), requestBody.length());
req->setRequestType(network::HttpRequest::Type::POST);
network::HttpClient::getInstance()->send(req);
requestBody
内容:
{
“batch”: [
{
“method”: GET
“relative_url”: http://…url to the direct download to avatar-image
},
{
“method”: GET
“relative_url”: http://…url to the direct download to avatar-image
}
],
“access_token”: “…”
}
(所有 relative_url 都有效,因为我在浏览器中对其进行了测试)我收到的数据响应示例:
[{
“code”: 200,
“headers”: [{
“name”: “Expires”,
“value”: “Sat, 01 Jan 2000 00:00:00 GMT”
}, {
“name”: “Cache-Control”,
“value”: “private, no-cache, no-store, must-revalidate”
}, {
“name”: “Access-Control-Allow-Origin”,
“value”: “ "
}, {
“name”: “Pragma”,
“value”: “no-cache”
}, {
“name”: “Strict-Transport-Security”,
“value”: “max-age=15552000; preload”
}, {
“name”: “ETag”,
“value”: ““3f2ef278dacb9dfc1c3827404a99ad8dfedc20cd””
}, {
“name”: “Vary”,
“value”: “Accept-Encoding”
}, {
“name”: “X-App-Usage”,
“value”: “{“call_count”:10,“total_cputime”:0,“total_time”:0}”
}, {
“name”: “Content-Type”,
“value”: “text/javascript; charset=UTF-8”
}, {
“name”: “Facebook-API-Version”,
“value”: “v2.12”
}],
“body”: “{“id”:“https://platform-lookaside.fbsbx.com/platform/profilepic”}”
}]
有了这个响应,我没有构建图像精灵的信息。我需要构建 1 个精灵图像的 responseData 示例:\377\330\377\340
解决方案
推荐阅读
- swift - 在 Realm Swift 中使用枚举
- sql - 我可以在 sql 语句的 IN 中使用 Varchar2(32767) 或 Varchar2 表吗
- reactjs - 如何使用参数弹出到上一个屏幕?
- sql - DateDiff 噩梦
- python - Kivy 如何赋予所有对象相同的基本功能
- java - 如何在java中对日期进行排序?
- tensorflow - ValueError:没有为任何变量 tensorflow 2.0 提供梯度
- c# - 无法在 Internet Explorer Web 驱动程序中找到更新面板的元素
- python - 两个 pyspark Dataframe 列之间的高效匹配
- java - 如何将对象数组转换为任意内容类型 T (Object[] -> T[])