0

我阅读了 facebook 文档并找到了一些登录 facebook 的方法。如何使用 FB sdk 3.5.x 使用嵌入式 WebView 登录对话框登录

在此处链接 facebook 文档

4

1 回答 1

0

它可能对您有用,下面还显示了一些 facebook 的委托方法

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [facebook handleOpenURL:url];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Although the SDK attempts to refresh its access tokens when it makes API calls,
    // it's a good practice to refresh the access token also when the app becomes active.
    // This gives apps that seldom make api calls a higher chance of having a non expired
    // access token.
    [[self facebook] extendAccessTokenIfNeeded];
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    NSLog(@"url->%@",url);
    return [self.facebook handleOpenURL:url];
}
- (BOOL)isFBLoggedIn
{
    return [facebook isSessionValid];
}

- (void)login
{
    if (![facebook isSessionValid])
    {
        [facebook authorize:[[NSArray alloc] initWithObjects:@"offline_access", nil]];

    } else
    {
        [facebook logout];
        [facebook authorize:[[NSArray alloc] initWithObjects:@"offline_access", nil]];
    }
}
- (void)fetchFBFriends
{
    [facebook requestWithGraphPath:@"me/friends" andDelegate:self];
}
-(void)fetchFbDetails
{
    [facebook requestWithGraphPath:@"me" andDelegate:self];
}
- (void)storeAuthData:(NSString *)accessToken expiresAt:(NSDate *)expiresAt
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:accessToken forKey:@"FBAccessTokenKey"];
    [defaults setObject:expiresAt forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
}

    NSString *strRes = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me?fields=name,username,email,gender,birthday,hometown,picture&access_token=%@",facebook.accessToken]] usedEncoding:&encoding error:&error];

    NSMutableDictionary *dirFbDetails = [[NSMutableDictionary alloc] initWithDictionary:[strRes JSONValue]];

    -(void)fbDidExtendToken:(NSString *)accessToken expiresAt:(NSDate *)expiresAt
    {
        NSLog(@"token extended");
        [self storeAuthData:accessToken expiresAt:expiresAt];
    }
    -(void)doFaceBookLogin
    {
        [self.facebook authorize:[NSArray arrayWithObjects:@"friends_birthday",@"user_birthday",@"email",@"publish_stream",nil]];

    }
    #pragma mark - FBRequestDelegate Methods

    - (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response
    {

    }
    - (void)request:(FBRequest *)request didLoad:(id)result
    {
    }

    - (void)request:(FBRequest *)request didFailWithError:(NSError *)error
    {


        NSLog(@"Err message: %@", [[error userInfo] objectForKey:@"error_msg"]);
        NSLog(@"Err code: %d", [error code]);
    }
于 2013-07-18T05:01:57.183 回答