Unable to request permission to upload video to facebook from iOS app
I'm using the social framework in iOS 6 to integrate facebook video
uploading into my app. However, nothing happens when I run the program,
and I instead receive this error:
"An active access token must be used to query information about the
current user.","type":"OAuthException","code":2500}}"
I've looked at similar SO questions, but I've only been able to deduce
that I'm not properly requesting permission to use facebook.
Below is my code, which I implemented from this tutorial. Through NSLogs,
I determined that BOOL granted is set to false.
- (void)uploadToFb {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// Specify App ID and permissions
NSDictionary *options = @{
ACFacebookAppIdKey: @"2************",
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
}
}];
NSURL *videourl = [NSURL
URLWithString:@"https://graph.facebook.com/me/videos"];
NSString *filePath = [outputURL path];
NSURL *pathURL = outputURL;
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSDictionary *params = @{
@"title": @"Face Puppets Video",
@"description": @"A funny video I made with the #FacePuppets iOS app."
};
SLRequest *uploadRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:videourl
parameters:params];
[uploadRequest addMultipartData:videoData
withName:@"source"
type:@"video/quicktime"
filename:[pathURL absoluteString]];
uploadRequest.account = facebookAccount;
[uploadRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *responseString = [[NSString alloc]
initWithData:responseData encoding:NSUTF8StringEncoding];
if(error){
NSLog(@"Error %@", error.localizedDescription);
}else
NSLog(@"%@", responseString);
}];
}
Also, I doubt that I properly added the app id in the plist, could this
also be a problem?
No comments:
Post a Comment