Fabricを使用してツイートするものを作りたいと思い、このコードを実行しました。
Swift
1 2import UIKit 3import TwitterKit 4 5class ViewController: UIViewController { 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 10 let logInButton = TWTRLogInButton { (session, error) in 11 if let unwrappedSession = session { 12 let alert = UIAlertController(title: "Logged In", 13 message: "User \(unwrappedSession.userName) has logged in", 14 preferredStyle: UIAlertControllerStyle.alert 15 ) 16 alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) 17 self.present(alert, animated: true, completion: nil) 18 19 //アクセストークンを表示 20 print(unwrappedSession.authToken) 21 //アクセストークンシークレットを表示 22 print(unwrappedSession.authTokenSecret) 23 24 //ここからツイート投稿のための準備 25 let endpoint = "https://api.twitter.com/1.1/statuses/update.json" 26 27 let client = TWTRAPIClient() 28 29 var clientError : NSError? 30 31 let params = ["status": "テスト"] 32 33 let request = client.urlRequest(withMethod: "POST", url: endpoint, parameters: params, error: &clientError) 34 35 client.sendTwitterRequest(request) { 36 (response, data, connectionError) -> Void in 37 if connectionError != nil { 38 print("エラー: \(connectionError)") 39 } 40 } 41 42 } else { 43 print("Login error: %@", error!.localizedDescription); 44 } 45 } 46 logInButton.loginMethods = [.webBased] 47 48 // TODO: Change where the log in button is positioned in your view 49 let button = logInButton 50 button.center = self.view.center 51 self.view.addSubview(button) 52 53 54 } 55 56 override func didReceiveMemoryWarning() { 57 super.didReceiveMemoryWarning() 58 // Dispose of any resources that can be recreated. 59 } 60 61} 62
OAuthでログインするところまでは成功したのですが
エラー: Optional(Error Domain=TwitterAPIErrorDomain Code=99 "Request failed: forbidden (403)" UserInfo={NSLocalizedFailureReason=Twitter API error : Unable to verify your credentials (code 99), TWTRNetworkingStatusCode=403, NSErrorFailingURLKey=https://api.twitter.com/oauth2/token, NSLocalizedDescription=Request failed: forbidden (403)})
このエラーが出てうまくいきません。
なぜこのエラーが出てしまうのか、どこを直せばいいのかをご教授いただけませんでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。