【问题标题】:How to use SLRequest for change via iOS to via <AppName>如何使用 SLRequest 通过 iOS 更改为通过 <AppName>
【发布时间】:2013-05-24 06:35:42
【问题描述】:

我浏览了许多链接和教程,但对我不起作用。 谁能解释我如何使用 SLRequest 通过 iOS 更改为通过 MyAppName ?逐步或给我一些链接,逐步提供此解决方案。

编辑:我试过了。以下是我的代码可能会有所帮助。

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    ACAccountType *facebookAccountType = [accountStore
                                          accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

        // Specify App ID and permissions
    NSDictionary *options = @{
                              ACFacebookAppIdKey: @"012345678912345",
                              ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
                              ACFacebookAudienceKey: ACFacebookAudienceFriends
                              };

    [accountStore requestAccessToAccountsWithType:facebookAccountType
                                          options:options completion:^(BOOL granted, NSError *e) {
                                              if (granted) {
                                                  NSArray *accounts = [accountStore
                                                                       accountsWithAccountType:facebookAccountType];
                                                  facebookAccount = [accounts lastObject];
                                              }
                                              else
                                                  {
                                                      // Handle Failure
                                                  }
                                          }];

    NSDictionary *parameters = @{@"message": @"My first iOS 6 Facebook posting "};

    NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];

    SLRequest *feedRequest = [SLRequest 
                              requestForServiceType:SLServiceTypeFacebook
                              requestMethod:SLRequestMethodPOST 
                              URL:feedURL 
                              parameters:parameters];

    feedRequest.account = self->facebookAccount;

    [feedRequest performRequestWithHandler:^(NSData *responseData, 
                                             NSHTTPURLResponse *urlResponse, NSError *error)
     {
         // Handle response
     }];
}

【问题讨论】:

  • “通过 iOS 更改为通过 MyAppName”没有意义。发布您拥有的代码并说出它做错了什么。

标签: ios facebook slrequest


【解决方案1】:

首先使用Facebook developer account setting设置你的facebook设置

然后从设备中重置您的模拟或删除应用程序。

添加并导入此框架

#import <Accounts/Accounts.h>
#import <Social/Social.h>
#import <AdSupport/AdSupport.h>
#import <FacebookSDK/FacebookSDK.h> 

使用此代码进行进一步处理

在你的class.h文件中

@property (nonatomic, strong)ACAccountStore *accountStore;

在你的class.m文件中

@synthesize accountStore;

- (IBAction)facebookButtonTouch:(id)sender {

    if (self.accountStore == nil) 
        self.accountStore = [[ACAccountStore alloc] init];


    __block ACAccount *facebookAccount = nil;

      ACAccountType *facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

      NSArray * permissions = @[@"publish_stream", @"publish_actions",@"email"];
      NSMutableDictionary *options = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"your app id", ACFacebookAppIdKey, permissions, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];



   [self.accountStore requestAccessToAccountsWithType:facebookAccountType
                                          options:options completion:^(BOOL granted, NSError *error)
     {
         if (granted)
         {
             NSArray *readPermissions = @[@"read_stream", @"read_friendlists"];
             [options setObject:readPermissions forKey: ACFacebookPermissionsKey];

             [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {
                 if(granted && error == nil) {
                     /**
                      * We now should have some read permission
                      * Now we may ask for write permissions or
                      * do something else.
                      **/
                 } else {
                     NSLog(@"error is: %@",[error description]);
                 }
             }];

             NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
             facebookAccount = [accounts lastObject];
         }
         else {

             NSLog(@"error.localizedDescription======= %@", error.localizedDescription);
         }

     }];

    NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
    facebookAccount = [accounts lastObject];



//-------------- start code for posting message on wall via SLRequest------------------
    NSDictionary *parameters = @{@"message": @"Hi Friends i m ....."};

    NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];

    SLRequest *feedRequest = [SLRequest
                              requestForServiceType:SLServiceTypeFacebook
                              requestMethod:SLRequestMethodPOST
                              URL:feedURL
                              parameters:parameters];

    feedRequest.account = facebookAccount;

    [feedRequest performRequestWithHandler:^(NSData *responseData,
                                             NSHTTPURLResponse *urlResponse, NSError *error)
     {
         NSLog(@"responseData %@",[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
     }];

//-------------- end code for posting message on wall via SLRequest------------------

}

希望对你有所帮助。谢谢

【讨论】:

  • 此代码将在FB的墙上发布按摩或者我们必须做其他事情??帮帮我,我对新的 FB 集成一无所知。我在上面做了,但什么也没发生。
  • 您好 python,感谢您的回复。让我明确您在应用程序中的要求。然后我将根据您的要求更新我的代码。你是想发消息还是只是想获取信息???
  • 嗨 python,我已经通过 SLRequest 更新了我的代码。请看一下,请让我知道您的反馈。谢谢
  • chandan 是的,我想在 FB 墙上发布消息。我什至尝试了新代码,它没有发布消息。我评论这个#import 然后应用程序也运行良好。没有得到结果。
  • 我的更新代码在这里工作正常。您不能一次又一次地发送相同的消息,因此您必须在每个帖子中更改它。请在我的答案的第一个链接“Facebook 开发者帐户设置”中检查您的开发者行为设置和 ACFacebookAppIdKey。它绝对可以帮助你。如果您仍然遇到此问题,请告诉我
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-16
  • 2020-07-09
  • 2014-10-16
  • 1970-01-01
  • 2021-11-14
  • 1970-01-01
相关资源
最近更新 更多