[英]How to get friends profile picture from gmail contacts?
I'm trying to import GMail contacts (friends list). 我正在尝试导入GMail联系人(朋友列表)。 I have got friends' mail id, name, and phone number, but if I tried to get the images it says "401 error".
我有朋友的邮件ID,姓名和电话号码,但是如果我尝试获取图像,则会显示“ 401错误”。
The code I have used is as follows: 我使用的代码如下:
GDataLink *photoLink = [contact photoLink];
NSLog(@"%@",photoLink);
NSURL *imageURL = [photoLink URL];
NSLog(@"image url = %@",imageURL);
How can I get friends' profile picture? 如何获取朋友的个人资料图片? Where did I go wrong?
我哪里做错了?
Looking at some other (public) code that's roughly the same as what you're doing , I see that you should be using an auth token with these photo links. 查看与您正在执行的操作大致相同的其他(公共)代码 ,我发现您应该在这些照片链接中使用身份验证令牌 。 Without that auth token, Google assumes you might be malicious and will send back a 401 error.
如果没有该身份验证令牌,Google会认为您可能是恶意的,并会发回401错误。
EG 例如
GDataLink *photoLink = [contact photoLink];
NSString *imageETag = [photoLink ETag];
if (imageETag == nil || ![mContactImageETag isEqual:imageETag]) {
if (imageETag != nil) {
// get an NSURLRequest object with an auth token
NSURL *imageURL = [photoLink URL];
GDataServiceGoogleContact *service = [self contactService];
// requestForURL:ETag:httpMethod: sets the user agent header of the
// request and, when using ClientLogin, adds the authorization header
NSMutableURLRequest *request = [service requestForURL:imageURL
ETag:nil
httpMethod:nil];
[request setValue:@"image/*" forHTTPHeaderField:@"Accept"];
GTMHTTPFetcher *fetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[fetcher setAuthorizer:[service authorizer]];
[fetcher beginFetchWithDelegate:self
didFinishSelector:@selector(imageFetcher:finishedWithData:error:)];
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.