大家好我需要一些帮助我需要Facebook令牌,必要的许可证才能显示生日用户......!这是我注册API的必要条件我正在使用所有方法查看Facebook开发人员,但我仍然有生日数据
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
- (IBAction)loginFaceboook:(id)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Process error
}
else if (result.isCancelled)
{
// Handle cancellations
}
else
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
// TODO: publish content.
} else {
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:@[@"publish_actions"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
//TODO: process error or result.
}];
}
if ([result.grantedPermissions containsObject:@"email"])
{
NSLog(@"result is:%@",result);
[self fetchUserInfo];
}
}
}];
}
-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
// NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"name, email, birthday"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(@"resultis:%@",result);
_auth_token = [[FBSDKAccessToken currentAccessToken]tokenString];
NSLog(@"Token Facebook is : %@",_auth_token);
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\\///\\\// /\\\///\\\///\\\\///\\\///\\\///\\\
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//[manager setResponseSerializer:[AFJSONResponseSerializer serializer]];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSDictionary *params = @{@"access_token":_auth_token};
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager POST:@"http:myUrl/api/facebook/" parameters:params success:^(NSURLSessionDataTask *operation, id responseObject) {
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
if (responseObject)
{
NSLog(@"POST data JSON returned: %@", responseObject);
NSLog(@"DATA SEND OK");
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"ERROR NO SEND DATA FROM FACEBOOK.. %@", error);
}];
_LoginFacebook.alpha=0;
Menu *VC2 = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[VC2 setModalTransitionStyle:(UIModalTransitionStyleCrossDissolve)];
[self presentViewController:VC2 animated:YES completion:nil ];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:self.auth_token forKey:@"tokenF"];
[prefs synchronize];
NSLog(@"Saved Toke %@",prefs);
}
else
{
NSLog(@"Error %@",error);
}
}];
}
}
来自控制台的信息数据是正确的,但交换x不提供个人信息
email = "xxxxxxxxxxxxxxxx@aol.com";
id = xxxxxxxxxxxxxxxxx;
name = "xxxxxxxxxxx";
Token Facebook is : xxxxxxxxxxxxxxxx......!
答案 0 :(得分:1)
编写此代码时
[login logInWithReadPermissions:@[@"email"]
添加&#34; public_profile&#34; 以及
[login logInWithReadPermissions:@[@"email",@"public_profile"]
检查它是否有效!
修改强>
正如CBroe所说,我们需要 user_birthday 权限,我想现在我们必须获得facebook的批准才能获得此许可
答案 1 :(得分:0)
这对我有用
- (IBAction)loginFaceboook:(id)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login setLoginBehavior:FBSDKLoginBehaviorNative];
[login logInWithReadPermissions:@[@"public_profile",@"user_birthday"] fromViewController:nil handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error)
{
// Process error
}
else if (result.isCancelled)
{
// Handle cancellations
}
else
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
// TODO: publish content.
} else {
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:@[@"publish_actions"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
//TODO: process error or result.
}];
}
if ([result.grantedPermissions containsObject:@"email"])
{
NSLog(@"result is:%@",result);
[self fetchUserInfo];
}
}
}];
}