我已经在Xcode6中集成了Facebook sdk (与swift)。在登录期间,我请求public_profile权限:
FBSession.openActiveSessionWithReadPermissions(["public_profile"], allowLoginUI: true, completionHandler: {
...
...
所以我请求用户的信息:
FBRequestConnection.startForMeWithCompletionHandler { (connection, user, error) -> Void in
...
...
为什么用户对象不包含个人资料图片?如何获取用户资料图片?这不是public_profile的一部分?
我得到了以下信息:
2015-01-25 01:25:18.858 Test[767:23804] {
"first_name" = xxx;
gender = xxx;
id = xxxxxxxxx;
"last_name" = xxxxxx;
link = "https://www.facebook.com/app_scoped_user_id/xxxxxxxxx/";
locale = "xxxxx";
name = "xxxxxxx xxxxxxx";
timezone = 1;
"updated_time" = "2013-12-21T18:45:29+0000";
verified = 1;
}
附言: xxx用于隐私
发布于 2015-01-25 08:58:32
个人资料图片实际上是公开的,您只需将用户id添加到Facebook指定的个人资料图片url地址即可,例如:
var userID = user["id"] as NSString
var facebookProfileUrl = "http://graph.facebook.com/\(userID)/picture?type=large"
这个特定的url地址应该返回用户个人资料图片的“大”版本,但in the docs还提供了更多的照片选项。
发布于 2015-07-09 14:28:45
如果你想得到更大的图片,只需将"type = large“替换为width=XX&height=XX即可
但是你能得到的最大的图片是原始图片
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me/picture?width=1080&height=1080&redirect=false"
parameters:nil
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(
FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if (!error)
{
NSLog(@"result = %@",result);
NSDictionary *dictionary = (NSDictionary *)result;
NSDictionary *data = [dictionary objectForKey:@"data"];
NSString *photoUrl = (NSString *)[data objectForKey:@"url"];
}
else
{
NSLog(@"result = %@",[error description]); }
}];
发布于 2015-05-20 19:16:42
@Brandon Gao solution给了我一个200X200的缩略图...为了获得更大的大小,我使用了FBSDKProfile
来获得一个带有大小的路径,这也更加模块化,并且不是硬编码(尽管我必须输入graph.facebook.com部分...)
let size = CGSize(width: 1080, height: 1080)
let path = FBSDKProfile.currentProfile().imagePathForPictureMode(.Normal, size: size)
let url = "https://graph.facebook.com/\(path)"
Alamofire.request(.GET, url, parameters: nil, encoding: ParameterEncoding.URL).response {
(request, response, data, error) -> Void in
if let imageData = data as? NSData,
let image = UIImage(data: imageData) {
self.buttonImage.setImage(image, forState: .Normal)
}
}
不知怎么的,我没有得到一张1080X1080的图像,FB给了我一张1117X1117的图像……:\
https://stackoverflow.com/questions/28131970
复制相似问题