【问题标题】:Parse Cloud code - Get Facebook profile picture fails with request code 302解析云代码 - 获取 Facebook 个人资料图片失败,请求代码为 302
【发布时间】:2014-12-09 21:44:08
【问题描述】:

我正在使用 Parse 并为我的应用程序编写自定义后端。我需要做的一件事是获取 Facebook 个人资料图片并将其存储为图像文件。但是我收到了 HTTP 错误代码 302。我理解错误 302 是由于重定向引起的。我正在寻找这种情况的解决方案。不,我无法从客户端获取图片并保存图像文件。我必须使用 Parse Cloud 代码来获取 Facebook 图片并保存。

这是我正在使用的代码

Parse.Cloud.define("fetchFacebookProfilePicture", function(request, response) {

   Parse.Cloud.useMasterKey();
   var Image = require("parse-image");
   var user = Parse.User.current();

   if (user == null) {
        response.error("user is NULL");
   }

   var profilePictureURL = "https://graph.facebook.com/"+user.get("facebookId") +"/picture?type=large&return_ssl_resources=1";

   return Parse.Cloud.httpRequest({
       url: profilePictureURL,
       method: "GET"
   }).then(function(response){
       //var image = new Image();
       response.success("All set");
   },function(error){
       response.error(error);
   });
});

这会返回以下错误

{"uuid":"229e2f43-7533-0149-3bbc-c69970e04d7e","status":302,"headers":{"Access-Control-Allow-Origin":"*","Cache-Control" :"private, no-cache, no-store, must-revalidate","Connection":"keep-alive","Content-Length":"0","Content-Type":"image/jpeg","日期":"格林威治标准时间 2014 年 12 月 9 日星期二 19:38:40","到期":"格林威治标准时间 2000 年 1 月 1 日星期六 00:00:00","Facebook-API-版本":"v1.0","位置":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpa1/v/t1.0-1/s200x200/1920432_10153903894020578_1014472787_n.jpg?oh=40dc964b1d8dd29f618387944050fff4&oe=55059D07&gda=1427550917_a067d3a93e9a1dd1a92a258258deb415","Pragma":"no-cache","X-FB-Debug":"XydW5s6z3jTiOzFBmToC63AquyYBCc5Ye5W6vX88j7NFwsubSqqDxiQQnta7Gp0JU/4VYKFN6wY4qufMN+vHPA==","X-FB-Rev",}}" "text":"","buffer":{"length":0,"parent":{"length":0},"offset":0},"cookies":{}}

【问题讨论】:

  • 您是否曾经为此找到解决方案/解决方法?
  • 不。我不是。如果有解决方案,那就太好了。

标签: facebook parse-platform


【解决方案1】:

您可以通过添加参数followRedirects 并将其设置为true 来解决此问题。例如,我的请求如下所示:

Parse.Cloud.httpRequest({ url: "https://graph.facebook.com/" + facebookId + "/picture", followRedirects: true, params: { type : 'large' } })

此外,如果 methodGET,则不必指定 method,因为这是隐含的。

希望这会有所帮助。

【讨论】:

  • 谢谢。我会试试这个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-20
  • 1970-01-01
  • 1970-01-01
  • 2011-09-01
  • 2014-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多