1

我真的花了几个小时试图解决这个问题,但没有成功!我只是希望能够从 facebook 读取任何用户的时间线(公共消息)...从技术上讲(为简单起见),我宁愿只使用 iOS sdk 中的框架(即不必使用 facebook 框架)。因此我目前只使用 Social.framework 和 Accounts.framework

到目前为止,我已经成功地阅读了当前登录用户(设备上标识的用户)的 facebook 时间线,但是当我尝试在以下 url @" https 中用 "ANOTHER_USER_ID" 替换 "me" 时: //graph.facebook.com/me/feed " 它只返回一个空数据字段(没有“消息”节点)。

“奇怪”的事实是,我可以使用@“ https://graph.facebook.com/cocacola/feed ”成功访问任何公司类型的提要(例如“可口可乐”)。

所以我的问题是如何获得“简单”用户的提要(例如“shireesh.asthana”),以便我可以阅读它的“消息”?

到目前为止我的过程:

  1. 在https://developers.facebook.com/上创建应用程序以获取 AppID
  2. 在我的代码中使用此 AppID 以便能够使用 SLRequest 发送请求

以下是我目前正在使用的代码:

ACAccountStore *account = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [account
                                  accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    // Specify App ID and permissions
    NSDictionary *options = @{
                              ACFacebookAppIdKey: @"1111111111111", // My AppID here
                              //ACFacebookPermissionsKey: @[@"read_stream"],
                              ACFacebookPermissionsKey: @[@"email", @"read_stream"],
                              ACFacebookAudienceKey:ACFacebookAudienceFriends
                              };

    [account requestAccessToAccountsWithType:accountType
                                     options:options completion:^(BOOL granted, NSError *error)
     {
         if (granted == YES)
         {
             NSArray *arrayOfAccounts = [account
                                         accountsWithAccountType:accountType];

             if ([arrayOfAccounts count] > 0)
             {
                 ACAccount *facebookAccount = [arrayOfAccounts lastObject];

                 // I want the messages and the author
                 NSDictionary *parameters = @{@"fields": @"message,from"};

                 NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/HERE_THE_USER_ID/feed"]; // Work with "cocacola" but not with "shireesh.asthana"

                 SLRequest *getRequest = [SLRequest
                                           requestForServiceType:SLServiceTypeFacebook
                                           requestMethod:SLRequestMethodGET
                                           URL:feedURL 
                                           parameters:parameters];

                 getRequest.account = facebookAccount;

                 [getRequest performRequestWithHandler:
                  ^(NSData *responseData, NSHTTPURLResponse
                    *urlResponse, NSError *error)
                  {
                      dataSource = [NSJSONSerialization
                                    JSONObjectWithData:responseData
                                    options:NSJSONReadingMutableLeaves
                                    error:&error];

                      // Reach the main queue to process result
                      dispatch_async(dispatch_get_main_queue(), ^{
                          NSLog(@"Read %d messages", [dataSource[@"data"] count]);
                          if ([dataSource[@"data"] count] != 0) {
                              // Do stuff in case of success...
                          } else {
                              // Do stuff in case of ERROR...
                          }
                      });
                  }];
             } else {
                 // Case of no facebook account on the device...
             }
         } else {
             // User don't grant the app to access its facebook info...
         }
     }];
4

1 回答 1

2

所以我的问题是如何获得“简单”用户的提要(例如“shireesh.asthana”),以便我可以阅读它的“消息”?

原因可能是——

  1. <user>没有公开帖子,

  2. 已在应用设置<user>关闭平台

(当然,<user>这里不是会话中的用户)

PS Shireesh Asthana(在 Facebook 工作),没有任何公开帖子

于 2013-09-13T12:32:15.667 回答