如何获取Facebook feed数据 [英] how to get facebook feeds data

查看:202
本文介绍了如何获取Facebook feed数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试登录用户供稿,要么是用户自己的供稿显示在他的墙上,要么是好友显示的最新供稿.

I am trying to get logged in users feeds either the users own feed shown on his wall or the latest feed shown of friends.

我使用旧程序检出了所有文章和其他文章,以获取Facebook所描述的提要. 现在我正在使用这种方法,但是没有得到任何东西

i checked out articles and other posts all of them using the old procedure to get the feed which was depricated by Facebook. now i am using this method but didng getting anything

NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
parameters[@"access_token"] = [FBSDKAccessToken currentAccessToken].tokenString;



FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                              initWithGraphPath:@"/me/feed"
                              parameters:parameters
                              HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
     if (error) {
         NSLog(@"%@",error);
     }else{
        // NSArray* posts = [result objectForKey:@"data"];
     }
}];

推荐答案

请使用以下代码在Facebook上共享文本. 在您的按钮点击事件上调用以下方法.

Please use the following code for sharing the text on Facebook. Call the following method on your button click event.

- (void)shareOnFacebook{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    if ([FBSDKAccessToken currentAccessToken] != nil)
    {
        NSDictionary *dict =  @{@"message":sharingMsg};
        FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]initWithGraphPath:@"/me/feed" parameters:dict HTTPMethod:@"POST"];
        [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
         {
             [MBProgressHUD hideHUDForView:self.view animated:YES];
             if (error != nil)
                 NSLog(@"%@",error.localizedDescription);
             else
                 NSLog(@"Success");
         }];
    }
    else{
        FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
        [loginManager setLoginBehavior:FBSDKLoginBehaviorSystemAccount];
        [loginManager logInWithReadPermissions:@[@"public_profile", @"email", @"user_friends"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
         {
             [MBProgressHUD hideHUDForView:self.view animated:YES];
             if (error)
                 [loginManager logOut];
             else if (result.isCancelled)
                 [loginManager logOut];
             else
             {
                 if ([result.grantedPermissions containsObject:@"publish_actions"])
                 {
                     [self grantPermissionFromFB];
                 }
                 else
                 {
                     [loginManager logInWithPublishPermissions:@[@"publish_actions"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
                      {
                          [MBProgressHUD hideHUDForView:self.view animated:YES];
                          if (error)
                              [loginManager logOut];
                          else if (result.isCancelled)
                              [loginManager logOut];
                          else
                          {
                              [self grantPermissionFromFB];
                          }
                      }];
                 }
             }
         }];
    }
}

- (void)grantPermissionFromFB{
    NSTimeInterval addTimeInterval = 60*60*24*365*50;
    NSDate *expireDate = [[NSDate date] dateByAddingTimeInterval:addTimeInterval];
    NSDate *refreshDate = [[NSDate date] dateByAddingTimeInterval:addTimeInterval];

    FBSDKAccessToken *newAccessToken = [[FBSDKAccessToken alloc] initWithTokenString:[[FBSDKAccessToken currentAccessToken] tokenString] permissions:nil declinedPermissions:nil appID:facebookAppID userID:[[FBSDKAccessToken currentAccessToken] userID] expirationDate:expireDate refreshDate:refreshDate];
    [FBSDKAccessToken setCurrentAccessToken:newAccessToken];

    NSDictionary *dict = @{@"message":sharingMsg};
    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]initWithGraphPath:@"/me/feed" parameters:dict HTTPMethod:@"POST"];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
     {
         [MBProgressHUD hideHUDForView:self.view animated:YES];
         if (error != nil)
             NSLog(@"%@",error.localizedDescription);
         else
             NSLog(@"Success");
     }];
}

这篇关于如何获取Facebook feed数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆