我正在尝试导入 GMail 联系人( friend 列表)。我有 friend 的邮件 ID、姓名和电话号码,但如果我尝试获取图片,它会显示“401 错误”。
我使用的代码如下:
GDataLink *photoLink = [contact photoLink];
NSLog(@"%@",photoLink);
NSURL *imageURL = [photoLink URL];
NSLog(@"image url = %@",imageURL);
如何获取好友的头像?我哪里做错了?
Looking at some other (public) code that's roughly the same as what you're doing ,我发现您应该在这些照片链接中使用 auth token。如果没有该身份验证 token ,Google 会假定您可能是恶意的,并会发回 401 错误。
例如
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
didFinishSelectorselector(imageFetcher:finishedWithData:error];
}
}
}
关于ios - 如何从 gmail 联系人中获取 friend 的个人资料图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15738482/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |