通过Facebook Graph API快速获取个人资料图片返回“不受支持的网址” [英] Getting profile picture with swift through Facebook Graph API return "unsupported URL"

查看:107
本文介绍了通过Facebook Graph API快速获取个人资料图片返回“不受支持的网址”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS开发一个应用程序,用户应该使用Facebook登录。所以我试图获取用户个人资料图片,但以下代码返回不支持的URL

I'm developing an app for iOS that user should login with facebook. So i'm trying to get the users profile picture but the following code is returning "unsupported URL"

FBRequestConnection.startWithGraphPath("\(userID)/picture?type=large&access_token=207613839327374|BgKi3AePtvg1oDO8GTbWqqLE_SM", completionHandler: { (connection, result, error) -> Void in
   if (error? != nil){
      NSLog("error = \(error)")
   }else{
      println(result)
   }
})






更新



以下更改:


UPDATE

The following change:

FBRequestConnection.startWithGraphPath("\(userID)/picture?type=large", completionHandler: { (connection, result, error) -> Void in
  if (error? != nil){
    NSLog("error = \(error)")
  }else{
    println(result)
  }
})

返回:

error = Error Domain=com.facebook.sdk Code=6 "Response is a non-text MIME type; endpoints that return images and other binary data should be fetched using NSURLRequest and NSURLConnection" UserInfo=0x786d4790


推荐答案

可以使用以下代码获取:

Able to get it using this code:

    // Get user profile pic
    var fbSession = PFFacebookUtils.session()
    var accessToken = fbSession.accessTokenData.accessToken
    let url = NSURL(string: "https://graph.facebook.com/me/picture?type=large&return_ssl_resources=1&access_token="+accessToken)
    let urlRequest = NSURLRequest(URL: url!)

    NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response:NSURLResponse!, data:NSData!, error:NSError!) -> Void in

        // Display the image
        let image = UIImage(data: data)
        self.imgProfile.image = image  

    }

这篇关于通过Facebook Graph API快速获取个人资料图片返回“不受支持的网址”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆