1

I goes through many link and tutorials but not working for me. Can anybody explain me How to use SLRequest for change via iOS to via MyAppName ?? step by step or give me some links which gives this solution in step by step.

EDIT: I have tried. Below is my code may be help.

    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
     }];
}
Kara
  • 6,115
  • 16
  • 50
  • 57
python
  • 1,407
  • 1
  • 15
  • 31
  • "change via iOS to via MyAppName" makes no sense. Post the code you have and say what it does wrong. – Wain May 24 '13 at 06:50

1 Answers1

1

First of all set you facebook setting using Facebook developer account setting

then reset your simular or delete app from device.

Add and import this frameworks

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

use this code for further process

in yourclass.h file

@property (nonatomic, strong)ACAccountStore *accountStore;

in yourclass.m file

@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------------------

}

i hope it will help you. Thanks

Community
  • 1
  • 1
chandan
  • 2,453
  • 23
  • 31
  • This Code will post massage on wall of FB or we have to do anything else?? Help me i don't know anything about new FB integration. I did above but nothing happening. – python May 24 '13 at 07:56
  • Hi python, thanks for reply. Let me clear with your requirements that you want in your application. Then i will update my code according to your requirement. You want to post message or just want to take feed??? – chandan May 24 '13 at 09:52
  • Hi python, i have updated my code with post message via SLRequest. Please have a look and please let me know your feed back. Thanks – chandan May 24 '13 at 10:29
  • chandan Yes i want post message on FB wall. I tried new code even, it is not posting message. i comment this #import then also app running fine. Not getting result. – python May 24 '13 at 11:04
  • My updated code working here fine. You can not send same message again and again so you have to change it with every post. Please check your developer act setting and ACFacebookAppIdKey inside my answer's first link "Facebook developer account setting". It defiantly helps you. Please let me know if you still facing this problem – chandan May 24 '13 at 11:11
  • AS response I am getting this {"error"{"message":"An Active access token must be used to query information about the current user","type":"OAuthException","code":2500}} Can you suggest where i am getting wrong. – python May 24 '13 at 11:33
  • Please this is due to facebook login. Please login in your facebook app from your setting then you can able to post. You are not logged in facebook app. Please login first then run your app again and then send message. It would work fine. Please let me know your feedback . Thanks – chandan May 24 '13 at 12:02
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/30564/discussion-between-chandan-and-python) – chandan May 24 '13 at 12:22
  • It is working, but big problem is when i changes Facebook account setting with other account it wont work for me ?? – python Jun 20 '13 at 10:08
  • Hi python plz check your ACFacebookAppIdKey and confirm it via developer account . Might be you will have to update plist value for it – chandan Jun 24 '13 at 09:00
  • Hi python plz let me know that is it working or not. So i can help u – chandan Jun 26 '13 at 05:04
  • Hi friend.. u help me lot. thanks first for that. It is working but when changed one fb account to other from setting, its giving OAuthException. Do u know any solution for this. Eager to accept ans. – python Jun 26 '13 at 09:12
  • Hi python, Sorry for late reply . Please disable deep linking from settings and use my updated code with different different app id and enjoy it. But always remind that before implementation of it delete existing app from device – chandan Jun 29 '13 at 09:13
  • Hi python, have you check it ? I am waiting for your response. Thanks – chandan Jul 01 '13 at 06:26
  • Sorry @python, I don't have. – chandan Oct 24 '13 at 04:30
  • Use this link for twitter https://dev.twitter.com/docs/ios/making-api-requests-slrequest – chandan Oct 24 '13 at 05:27