ios - 如何从 gmail 联系人中获取 friend 的个人资料图片?
<p><p>我正在尝试导入 GMail 联系人( friend 列表)。我有 friend 的邮件 ID、姓名和电话号码,但如果我尝试获取图片,它会显示“401 错误”。</p>
<p>我使用的代码如下:</p>
<pre><code>GDataLink *photoLink = ;
NSLog(@"%@",photoLink);
NSURL *imageURL = ;
NSLog(@"image url = %@",imageURL);
</code></pre>
<p>如何获取好友的头像?我哪里做错了?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p> <a href="https://github.com/nparry/gdata-objectivec-client/blob/master/Examples/ContactsSample/ContactsSampleWindowController.m" rel="noreferrer noopener nofollow">Looking at some other (public) code that's roughly the same as what you're doing</a> ,我发现您应该在这些照片链接中使用 <strong><em>auth token</em></strong>。如果没有该身份验证 token ,Google 会假定您可能是恶意的,并会发回 401 错误。</p>
<p>例如</p>
<pre><code> GDataLink *photoLink = ;
NSString *imageETag = ;
if (imageETag == nil || !) {
if (imageETag != nil) {
// get an NSURLRequest object with an auth token
NSURL *imageURL = ;
GDataServiceGoogleContact *service = ;
// 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];
;
GTMHTTPFetcher *fetcher = ;
];
[fetcher beginFetchWithDelegate:self
didFinishSelector:@selector(imageFetcher:finishedWithData:error:)];
}
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何从 gmail 联系人中获取 friend 的个人资料图片?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15738482/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15738482/
</a>
</p>
页:
[1]