iOS-微博登入回撥不成功的解決

weixin_34075551發表於2018-08-28

之前微博登入正常實現,後來回撥到客戶端就是客戶端不執行下一步操作
原因 : 不知道哪一天給貼上上了不知道在哪個地方複製的代理方法
解決 : 刪掉就好了
要刪的!!!!!

-(void)request:(WBHttpRequest *)request didReceiveResponse:(NSURLResponse *)response{
    
}
/**
 收到一個來自微博Http請求的網路返回
 
 @param data 請求返回結果
 */

- (void)request:(WBHttpRequest *)request didFinishLoadingWithDataResult:(NSData *)data{
    
}

/**
 收到快速SSO授權的重定向
 
 @param URI
 */

- (void)request:(WBHttpRequest *)request didReciveRedirectResponseWithURI:(NSURL *)redirectUrl{
    
}

[需要的回撥! 微博登入和微博分享都會走這個回撥,if語句進行區分] 下面的是我之前的,有一些自己封裝的東西懶得刪了,直接跳過看吧

#pragma mark - sina
- (void)didReceiveWeiboRequest:(WBBaseRequest *)request{
    
}
- (void)didReceiveWeiboResponse:(WBBaseResponse *)response{
    self.sinaResponse = [[SSSocialUserInfoResponse alloc] init];
    self.sinaResponse.platformType = SSSocialPlatformTypeSina;
    if ( [response isKindOfClass:[WBAuthorizeResponse class]] && self.isShared == NO) {
        // 登入授權
        if (response.statusCode == WeiboSDKResponseStatusCodeSuccess ) {
            NSString *token = [(WBAuthorizeResponse *)response accessToken];
            NSString *userid = [(WBAuthorizeResponse *)response userID];
            
            self.sinaResponse.statusCode = SSSocialResponseStatusCodeSuccess;
            self.sinaResponse.openid = userid;
            self.sinaResponse.accessToken = token;
            
            NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:2];
            [params setObject:token forKey:@"access_token"];
            [params setObject:userid forKey:@"uid"];
            
            //傳送請求 獲取各種資料 對應的URL和請求方式heepMethod是不同的 詳細的參考微博開放平臺
            [WBHttpRequest requestWithURL:@"https://api.weibo.com/2/users/show.json" httpMethod:@"GET" params:params delegate:self withTag:@"getUserInfo"];
        }else if (response.statusCode == WeiboSDKResponseStatusCodeUserCancel){
            self.sinaResponse.statusCode = SSSocialResponseStatusCodeUserCancel;
            self.sinaResponse.error = @"取消操作";
            _userInfoBlock(self.sinaResponse);
            if (self.callbackResponse != nil) {
                self.callbackResponse(@"cancel", nil);
            }
        }else{
            self.sinaResponse.statusCode = SSSocialResponseStatusCodeAuthDeny;
            self.sinaResponse.error = @"授權失敗";
            _userInfoBlock(self.sinaResponse);
            if (self.callbackResponse != nil) {
                self.callbackResponse(@"failed", nil);
            }
        }
    }else{
      // 分享
        self.isShared = NO;
        if (response.statusCode == WeiboSDKResponseStatusCodeSuccess) {
          if (self.callbackResponse != nil) {
            self.callbackResponse(@"success", nil);
        }
    }
    }
   
}
#pragma mark - WBHttpRequestDelegate
/**
 收到一個來自微博Http請求的網路返回
 
 @param result 請求返回結果
 */
-(void)request:(WBHttpRequest *)request didFinishLoadingWithResult:(NSString *)result {
    
    NSData *data = [result dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    if (dic == nil) {
        self.sinaResponse.statusCode = SSSocialResponseStatusCodeAuthDeny;
        self.sinaResponse.error = @"授權失敗";
        _userInfoBlock(self.sinaResponse);
        return;
    }
    self.sinaResponse.statusCode = 0;
    self.sinaResponse.nickname = [dic objectForKey:@"screen_name"];
    self.sinaResponse.iconurl = [dic objectForKey:@"profile_image_url"];
    _userInfoBlock(self.sinaResponse);
}
/**
 收到一個來自微博Http請求失敗的響應
 
 @param error 錯誤資訊
 */
- (void)request:(WBHttpRequest *)request didFailWithError:(NSError *)error{
    self.sinaResponse.statusCode = SSSocialResponseStatusCodeAuthDeny;
    self.sinaResponse.error = @"授權失敗";
    _userInfoBlock(self.sinaResponse);
}

相關文章