InstagramでのOAuthがしたいのですが、実機でインスタグラムのログイン画面をwebview上に表示し、ログインすると、インスタグラムが開かれ、更にインスタグラムがサファリを開き、リダイレクトされたURLに含まれるaccessTokenが取得できません。シミュレーターでは、インスタグラムのアプリがないためか、うまくaccessTokenを取得し、ユーザーの情報を取得することができました。何か良い方法はありませんか?ちなみに、InstagramKitというのを使用しています。お力を貸してくださると助かります..>_<
Swift
1 2 func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { 3 4 do{ 5 print(request.URL!) 6 guard let _ = try InstagramEngine.sharedEngine().receivedValidAccessTokenFromURL(request.URL!) as? AnyObject else { 7 // success! 8 UIView.animateWithDuration(0.5, animations: { () -> Void in 9 self.webView.frame = CGRectMake(0,CGRectGetHeight(self.view.frame), CGRectGetWidth(self.view.frame),CGRectGetHeight(self.view.frame)) 10 }) 11 12 let urlArray = request.URL!.absoluteString.componentsSeparatedByString("=") 13 let accessToken = urlArray.last 14 let accessTokenArray = accessToken?.componentsSeparatedByString(".") 15 let instagramId = accessTokenArray?.first 16 let apiURL = "https://api.instagram.com/v1/users/self/?access_token=\(accessToken!)" 17 self.getInstagramUsersDataWithURL(apiURL); 18 19 return true 20 } 21 } 22 catch let error as NSError { 23 print(error.localizedDescription) 24 return true 25 } 26 27 return true; 28 }
あなたの回答
tips
プレビュー