我正在使用 iOS 6 中的社交框架将 facebook 视频上传集成到我的应用程序中。但是,当我运行程序时没有任何反应,而是收到以下错误:
操作无法完成。(com.apple.accounts 错误 6。)
"必须使用活动访问令牌来查询有关当前用户的信息。","type":"OAuthException","code":2500}}"
下面是我的代码,前半部分是我从本教程中实现的。granted
设置为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
{
NSLog(@"Error %@", e.localizedDescription); }
}
}];
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);
}];
}