iOS Facebook 获取用户邮箱
<p><p>我尝试了 2000 多种方法来获取用户的电子邮件。我无法从 Facebook SDK 的图形 API 中获取它。它不包含电子邮件属性。我还尝试将电子邮件属性手动添加到 FB 框架中,但没有任何反应。是否可以下载第一个兼容 iOS 7 的 FB SDK?它仍然具有电子邮件属性,不是吗?或者有没有其他方法可以获得真实的电子邮件,我必须与他们合作。我不需要 [email protected]。</p>
<p>感谢您的建议。</p>
<p>编辑</p>
<pre><code>NSArray *permissions = @[@"email", @"public_profile"];
[PFFacebookUtils logInWithPermissions:permissions block:^(PFUser *user, NSError *error) {
if (!user) {
if (!error) {
NSLog(@"The user cancelled the Facebook login.");
} else {
NSLog(@"An error occurred: %@", error.localizedDescription);
}
if () {
;
}
} else {
if (user.isNew) {
NSLog(@"User signed up and logged in through Facebook!");
} else {
NSLog(@"User logged in through Facebook!");
}
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
PFUser *usere = ;
forKey:@"name"];
forKey:@"surname"];
// forKey:@"mail"];
;
NSLog(@"user info: %@", result);
}
}];
}
if () {
;
}
}];
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我没有图形 API 的代码,</p>
<p>但是对于新的 facebook sdk 版本 3,我有相应的代码。</p>
<pre><code>-(void)openFbSession
{
[.session closeAndClearTokenInformation];
NSArray *permissions = ;
.session = [ initWithPermissions:permissions];
[.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if(!error)
{
NSLog(@"success");
;
}
else
{
NSLog(@"failure");
}
}];
}
</code></pre>
<p>对于所有信息,myFbInfo 方法是</p>
<pre><code>-(void)myFbInfo
{
.session];
[ startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
if (error) {
// Handle error
}
else {
//NSString *userName = ;
//NSString *userImageURL = ];
NSLog(@"Name : %@",);
NSLog(@"first name : %@",);
NSLog(@"Last name : %@",);
NSLog(@"ID : %@",);
NSLog(@"username : %@",);
NSLog(@"Email : %@",);
NSLog(@"user all info : %@",FBuser);
}
}];
}
</code></pre>
<hr/>
<p>编辑</p>
<hr/>
<p>在 appdelegate.h 中</p>
<pre><code>@property (strong, nonatomic) FBSession *session;
</code></pre>
<p>在 appdelegate.m 中</p>
<pre><code>- (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation
{
//NSLog(@"FB or Linkedin clicked");
return ;
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
;
}
- (void)applicationWillTerminate:(UIApplication *)application
{
;
}
</code></pre></p>
<p style="font-size: 20px;">关于iOS Facebook 获取用户邮箱,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24890798/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24890798/
</a>
</p>
页:
[1]