|
|
#1 |
|
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 05:58 PM. Reason: Editing code |
|
|
|
0
|
|
|
#2 |
|
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. |
|
|
|
0
|
|
|
#3 | |
|
Quote:
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);
}];
}
Last edited by newtoiphonesdk; Jan 8, 2013 at 10:37 AM. Reason: Update |
||
|
|
0
|
|
|
#4 |
|
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!". |
|
|
|
0
|
|
|
#5 | |
|
Quote:
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 12:37 PM. Reason: UPDATE of HTTP Response |
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 06:00 AM.







Linear Mode
