【问题标题】:how to get facebook feeds data如何获取 Facebook 提要数据
【发布时间】:2016-05-19 10:08:52
【问题描述】:

我正在尝试获取登录用户的订阅源,要么是他墙上显示的用户自己的订阅源,要么是朋友显示的最新订阅源。

我使用旧程序查看了所有文章和其他帖子,以获取被 Facebook 贬低的提要。 现在我正在使用这种方法,但没有得到任何东西

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

【问题讨论】:

  • 设置 HTTPMethod : @"POST"
  • 当将其更改为发布此错误消息时“com.facebook.sdk:FBSDKErrorDeveloperMessageKey=(#200) 用户尚未授权应用程序执行此操作”
  • 你有“publish_actions”的权限吗?
  • "publish_actions" 权限不受支持...
  • 请试试我的回答。如果对你有帮助。

标签: ios objective-c facebook-graph-api fbsdk


【解决方案1】:

请使用以下代码在 Facebook 上分享文字。 在您的按钮单击事件上调用以下方法。

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

【讨论】:

  • 感谢您的回复....根据您的回复,我对代码进行了一些更改,它对我有用...通过使用此 url :- ""NSString *urlString1 = [NSString stringWithFormat :@"graph.facebook.com/…;""
  • 我最后一天搜索了很多,以寻找一个简单的工作示例,说明如何通过我的 Objective-C iOS 应用程序通过 FB 的 Graph API 发布到我的 FB 帐户。最后,我看到了你的代码,我明白了。甜的!谢谢。
  • 最欢迎@Gallymon
猜你喜欢
  • 1970-01-01
  • 2017-09-10
  • 2012-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-06
  • 1970-01-01
相关资源
最近更新 更多