首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过iOS通过<AppName>使用SLRequest进行更改

如何通过iOS通过<AppName>使用SLRequest进行更改
EN

Stack Overflow用户
提问于 2013-05-24 14:35:42
回答 1查看 1.4K关注 0票数 1

我经历了许多链接和教程,但对我来说并不起作用。谁能解释一下如何通过iOS到via MyAppName使用SLRequest进行更改??一步一步或给我一些链接,给这个解决方案在一步一步。

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

代码语言:javascript
复制
    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
     }];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-24 15:22:10

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

然后重置你的模拟器或从设备上删除应用程序。

添加并导入此框架

代码语言:javascript
复制
#import <Accounts/Accounts.h>
#import <Social/Social.h>
#import <AdSupport/AdSupport.h>
#import <FacebookSDK/FacebookSDK.h> 

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

在class.h文件中

代码语言:javascript
复制
@property (nonatomic, strong)ACAccountStore *accountStore;

在class.m文件中

代码语言:javascript
复制
@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------------------

}

我希望它能对你有所帮助。谢谢

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16728969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档