[英]How to get Email param of facebook using SLRequest in iOS Social Framework
[英]how to get read permission before publishing permission for uploading video on Facebook using SLRequest?
我只是想將Facebook共享集成到我的應用程序中,我的應用程序的最終產品是一個視頻,因此我想到的是與朋友上傳和共享最終編輯,我正在將本機社交框架與ACAccount Framework結合使用,以使我的應用程序正常工作來自Facebook的似乎有些奇怪的邏輯,我需要在請求publish_stream許可之前先請求讀取許可,並且它們不能緊隨其后(在某處讀取),我的問題是我應該在哪里以及如何在我的代碼中實現此邏輯,這里我的代碼
ACAccountStore* accountStore = [[ACAccountStore alloc] init];
NSDictionary *options = @{
ACFacebookAppIdKey: @"My app ID",
ACFacebookPermissionsKey: @[@"user_birthday"],
ACFacebookAudienceKey: ACFacebookAudienceOnlyMe
};
ACAccountType *facebookAccountType = [accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accounts = [accountStore
accountsWithAccountType:facebookAccountType];
ACAccount * facebookAccount = [accounts lastObject];
NSLog(@"access to facebook account ok %@", facebookAccount.username);
NSData *videoData = [NSData dataWithContentsOfFile:[_fURL absoluteString]];
NSLog(@"%@",[_fURL absoluteString]);
NSLog(@"video size = %d", [videoData length]);
NSDictionary *params = @{
@"title": @"Me being silly",
@"description": @"Me testing the video upload to Facebook with the new system."
};
NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:requestURL
parameters:params];
[request addMultipartData:videoData
withName:@"source"
type:@"video/quicktime"
filename:[_fURL absoluteString]];
request.account = facebookAccount;
[request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response,NSError * error){
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"response = %@", responseString);
}];
是的,我缺少發布流權限,但我似乎無法弄清楚應將其放在哪里,整個代碼位於一種方法下,當用戶按下按鈕時會調用該方法
這很簡單。 那是我的實現:
- (void)requestAccessToFacebookAccountWithCompletionHandler:(QCFacebookCommunicatorCompletionHandler)completionHandler {
[[self accountStore] requestAccessToAccountsWithType:[self accountType] options:[self facebookAccountAccessRequestOptionsForReadStreamPermission] completion:^(BOOL accessForReadingGranted, NSError *error) {
if (accessForReadingGranted) {
[[self accountStore] requestAccessToAccountsWithType:[self accountType] options:[self facebookAccountAccessRequestOptionsForPublishStreamPermission] completion:^(BOOL accessForWrittingGranted, NSError *error) {
if (accessForWrittingGranted) {
completionHandler(YES, nil);
} else {
completionHandler(NO, [error userInfo]);
}
}];
} else {
completionHandler(NO, [error userInfo]);
}
}];
}
我只是使用輔助方法來返回帶有選項的字典,其他內容與您的相似。
然后,您可以粘貼負責視頻上傳的代碼而不是completionHandler調用,或者可以使用此實現,並且僅在completionHandler中成功== YES的情況下上傳視頻。
希望能幫助到你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.