Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 7, 2013, 06:57 PM   #1
newtoiphonesdk
macrumors 6502a
 
Join Date: Jul 2010
Auto-post to Facebook iOS 6 with SLRequest

I want my blog app to be able to automatically post to the user's Facebook wall when they view an article. I have the following code in, and the first time it asks for permission to post, but it never actually does. What am I doing wrong?
Code:
-(void)requestPermissions
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    __block ACAccount *facebookAccount = nil;

    ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    // Specify App ID and permissions
    NSDictionary *options = @{
ACFacebookAppIdKey: @"MYAPPID",
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": html};

    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)
     {
         // Handle response
     }];
}

Last edited by newtoiphonesdk; Jan 7, 2013 at 06:58 PM. Reason: Editing code
newtoiphonesdk is offline   0 Reply With Quote
Old Jan 7, 2013, 11:52 PM   #2
xArtx
macrumors 6502a
 
Join Date: Mar 2012
If you go to post with it, or authorise again, does the FB app tell you:
"You have already authorised applicationname Press Okay to Continue"?

I don't claim to be an expert, but I have played around with FB SDK
with success, and that's the screen I get when my app logs in.
It occurs to me that otherwise, the app's permission has failed.
xArtx is offline   0 Reply With Quote
Old Jan 8, 2013, 10:40 AM   #3
newtoiphonesdk
Thread Starter
macrumors 6502a
 
Join Date: Jul 2010
Quote:
Originally Posted by xArtx View Post
If you go to post with it, or authorise again, does the FB app tell you:
"You have already authorised applicationname Press Okay to Continue"?

I don't claim to be an expert, but I have played around with FB SDK
with success, and that's the screen I get when my app logs in.
It occurs to me that otherwise, the app's permission has failed.
EDIT: After more testing, realized have to ask for basic permissions BEFORE asking permission to post. I did this and edited the code to what is below, and get permissions granted, but still not posting.
Code:
-(void)requestPermissions
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    __block ACAccount *facebookAccount = nil;
    
    ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    
    // Specify App ID and permissions
    NSDictionary *options = @{
ACFacebookAppIdKey: @"MYAPPID",
ACFacebookPermissionsKey: @[@"email", @"user_about_me", @"user_likes"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
    };
    
    [accountStore requestAccessToAccountsWithType:facebookAccountType
                                          options:options completion:^(BOOL granted, NSError *e)
     {
         if (granted) {
            
             NSDictionary *options2 = @{
         ACFacebookAppIdKey: @"MYAPPID",
         ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
         ACFacebookAudienceKey: ACFacebookAudienceFriends
             };
             [accountStore requestAccessToAccountsWithType:facebookAccountType options:options2 completion:^(BOOL granted, NSError *error) {
                 if (granted) {
                     NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];
                     
                     facebookAccount = [accounts lastObject];                 }
                 else {
                     NSLog(@"Access denied 2");
                     NSLog(@"%@", [error description]);
                 }
             }];
         } else {
             NSLog(@"Error: %@", [e description]);
             NSLog(@"Access denied");
         }
     }];
    
    NSDictionary *parameters = @{@"message": @"This is a test"};
    
    NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
    
    SLRequest *feedRequest = [SLRequest
                              requestForServiceType:SLServiceTypeFacebook
                              requestMethod:SLRequestMethodPOST
                              URL:feedURL
                              parameters:parameters];
    NSLog(@"AnythingHere?");
    feedRequest.account = facebookAccount;
    
    [feedRequest performRequestWithHandler:^(NSData *responseData,
                                             NSHTTPURLResponse *urlResponse, NSError *error)
     {
         // Handle response
         NSLog(@"%@%@%@", error, responseData, urlResponse);
     }];
}
EDIT:So, the issue before was you can't get permission to post until after you already have permission for basic info. So, I did that and edited the code above to show this. However, still nothing is happening on Facebook. Error in log comes back null for the final part. Any thoughts on this?

Last edited by newtoiphonesdk; Jan 8, 2013 at 11:37 AM. Reason: Update
newtoiphonesdk is offline   0 Reply With Quote
Old Jan 8, 2013, 11:37 AM   #4
xArtx
macrumors 6502a
 
Join Date: Mar 2012
You wouldn't have seen that screen if you didn't get permission then.
I'm using an old FB SDK that still compiles, and don't know much about it,
but if you get to that screen, it might tell you any problem with your app
at the FB end.
To this day it complains my app has no bundle ID because I never filled it
in, but it does always log in and post.
I only used a sample to post in a fashion not possible for a Human end user
with app name "MyFirstName's Real Life!".
xArtx is offline   0 Reply With Quote
Old Jan 8, 2013, 11:54 AM   #5
newtoiphonesdk
Thread Starter
macrumors 6502a
 
Join Date: Jul 2010
Quote:
Originally Posted by xArtx View Post
You wouldn't have seen that screen if you didn't get permission then.
I'm using an old FB SDK that still compiles, and don't know much about it,
but if you get to that screen, it might tell you any problem with your app
at the FB end.
To this day it complains my app has no bundle ID because I never filled it
in, but it does always log in and post.
I only used a sample to post in a fashion not possible for a Human end user
with app name "MyFirstName's Real Life!".
Sorry, I had made a couple edits and updates to code since your earlier post and my reply. Did you see the edits? I got the permissions, it no longer asks for permissions, but still won't post message, and no error messages.

Finally got HTTP response code of 400. Also An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

Last edited by newtoiphonesdk; Jan 8, 2013 at 01:37 PM. Reason: UPDATE of HTTP Response
newtoiphonesdk is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPhone: Tweak to stop Facebook Video Auto-Play From A Buick 8 Jailbreaks and iOS Hacks 7 Jan 28, 2014 06:49 PM
Still No Quick Post FaceBook/Twitter iOS 7 GM rnbgrilla iOS 7 2 Sep 11, 2013 03:12 AM
Disable facebook auto-fill login mattbm iPhone and iPod touch Apps 0 Apr 21, 2013 07:41 AM
SLRequest Facebook Error 2500 Handling newtoiphonesdk iPhone/iPad Programming 0 Jan 8, 2013 08:18 PM
turn off facebook auto message UKBeast iPhone 4 Dec 16, 2012 08:01 PM

Forum Jump

All times are GMT -5. The time now is 12:20 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC