how to get facebook feeds data

别说谁变了你拦得住时间么 提交于 2019-12-11 10:18:49

问题


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.

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"];
     }
}];

回答1:


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");
     }];
}


来源:https://stackoverflow.com/questions/35291789/how-to-get-facebook-feeds-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!