我最近開始使用Facebook SDK 3.1,並遇到一些使用openActiveSessionWithReadPermissions
登錄的問題。openActiveSessionWithReadPermissions不會自動登錄
實際上,登錄功能完美無缺,如果有緩存的令牌可用,它將登錄而不會呈現Facebook用戶界面,如果沒有,則會顯示用戶界面。
我撥打電話reauthorizeWithPublishPermissions
後出現問題。如果我撥打reauthorizeWithPublishPermissions
,然後關閉並重新打開該應用程序,並致電openActiveSessionWithReadPermissions
,它會顯示Facebook用戶界面,並要求用戶說「是的,我擁有讀取權限」,即使存在可用的緩存令牌。
如果我打電話給reauthorizeWithPublishPermissions
,它只會錯誤地顯示Facebook UI,否則一切正常。
開放讀碼:
[FBSession openActiveSessionWithReadPermissions:readpermissions allowLoginUI:YES
completionHandler:^(FBSession *aSession, FBSessionState status, NSError *error) {
[self sessionStateChanged:[FBSession activeSession] state:status error:error];
if (status != FBSessionStateOpenTokenExtended) {
// and here we make sure to update our UX according to the new session state
FBRequest *me = [[FBRequest alloc] initWithSession:aSession
graphPath:@"me"];
[me startWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *aUser,
NSError *error) {
self.user = aUser;
aCompletionBlock(aSession, status, error);
}];
}
}];
的sessionStateChanged功能:
- (void)sessionStateChanged:(FBSession *)aSession state:(FBSessionState)state error:(NSError *)error {
if (aSession.isOpen) {
// Initiate a Facebook instance and properties
if (nil == self.facebook || state == FBSessionStateOpenTokenExtended) {
self.facebook = [[Facebook alloc]
initWithAppId:FBSession.activeSession.appID
andDelegate:nil];
// Store the Facebook session information
self.facebook.accessToken = FBSession.activeSession.accessToken;
self.facebook.expirationDate = FBSession.activeSession.expirationDate;
}
} else {
// Clear out the Facebook instance
if (state == FBSessionStateClosedLoginFailed) {
[FBSession.activeSession closeAndClearTokenInformation];
}
self.facebook = nil;
}
}
發佈號召,用空aPublishAction來進行測試:
- (void)doPublishAction:(void(^)(FBSession *aSession, NSError *error))aPublishAction {
if ([FBSession.activeSession.permissions
indexOfObject:@"publish_actions"] == NSNotFound) {
NSArray *writepermissions = [[NSArray alloc] initWithObjects:
@"publish_stream",
@"publish_actions",
nil];
[[FBSession activeSession]reauthorizeWithPublishPermissions:writepermissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *aSession, NSError *error){
if (error) {
NSLog(@"Error on public permissions: %@", error);
}
else {
aPublishAction(aSession, error);
}
}];
}
else {
// If permissions present, publish the story
aPublishAction(FBSession.activeSession, nil);
}
}
感謝事先做好準備,我會感謝任何和所有的幫助!
我認爲publish_actions是你所需要的。我認爲它現在包含publish_stream。 – SAHM
你有沒有找到這個解決方案?我有完全相同的問題。 – Casey
從來沒有找到解決方案,我們實際上停止了需要發佈權限,所以我們從不需要找到解決方案。 –