繁体   English   中英

如何使用iOS社交框架读取任何Facebook用户公共时间轴?

[英]How to read any facebook user public timeline using iOS Social framework?

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

到目前为止,我成功完成的工作是,当我尝试通过以下网址@“ https ”中的“ ANOTHER_USER_ID”支持“ me”时,请阅读当前登录用户(在设备上标识的用户)的Facebook时间轴: //graph.facebook.com/me/feed “,它仅返回一个空的数据字段(无“ message”节点)。

“奇怪”的事实是,我可以使用@“ 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...
         }
     }];

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

原因可能是-

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

  2. <user>在“ 应用程序设置”中具有“关闭平台

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM