2017-10-30 4 views
1

iOSでTwitter API接続をObjective- C.私が使用しているコード:私AppDelegateでiOS:エラーメッセージ "[TwitterKit]に"ユーザー認証トークンを取得できませんでした "というエラーメッセージが表示されました:エラードメイン= TWTRLogInErrorDomainコード= -1"

[[Twitter sharedInstance] logInWithCompletion:^ 
(TWTRSession *session, NSError *error) { 
    if (session) { 
     NSLog(@""); 
    }}]; 

:OpenURLのが呼ばれることはありませんI正確なこと

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
//Twitter 
    [[Twitter sharedInstance] startWithConsumerKey:@"z0F**************cg" consumerSecret:@"PJu*******************N6W"]; 

- (BOOL)application:(UIApplication *)app 
      openURL:(NSURL *)url 
      options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options { 
     return [[Twitter sharedInstance] application:app openURL:url options:options]; 

    return NO; 
} 

私は理解していないいくつかのエラーメッセージを得る:

Error Domain=TWTRNetworkingErrorDomain Code=-1011 "Request failed: unauthorized (401)" UserInfo={NSLocalizedFailureReason=Twitter API error : <?xml version="1.0" encoding="UTF-8"?> 
<hash> 
    <error>Desktop applications only support the oauth_callback value 'oob'</error> 
    <request>/oauth/request_token</request> 
</hash> 
(code (null)), TWTRNetworkingStatusCode=401, NSErrorFailingURLKey=https://api.twitter.com/oauth/request_token, NSLocalizedDescription=Request failed: unauthorized (401)} 

AND:それが接続されていないようだ

[TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?> 
<hash> 
    <error>Desktop applications only support the oauth_callback value 'oob'</error> 
    <request>/oauth/request_token</request> 
</hash> 
" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?> 
<hash> 
    <error>Desktop applications only support the oauth_callback value 'oob'</error> 
    <request>/oauth/request_token</request> 
</hash> 
} 

を、私はスウィフトに多くのものを見に、しかし、 Objective-Cでは何もありません。

ありがとうございます。

答えて

1

あなたはユーザーがログインしていることを手動https://dev.twitter.com/twitterkit/ios/access-rest-api

チェック読めば:あなたはそれを助ける、ことを確認した場合、画像については

TWTRLogInButton *logInButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) { 
     if (session) { 
      NSLog(@"signed in as %@", [session userName]); 
     } else { 
      NSLog(@"error: %@", [error localizedDescription]); 
     } 
    }]; 
    logInButton.center = self.view.center; 
    [self.view addSubview:logInButton]; 

NSString *userID = [Twitter sharedInstance].sessionStore.session.userID; 
     TWTRAPIClient *client = [[TWTRAPIClient alloc] initWithUserID:userID]; 

をこれらの行を追加します。あなた:Posting image to twitter using twitterkit

[self tweetImage: [UIImage imageNamed:@"buttonRenault.png"]]; 
+0

、それは非常にうまく機能し、非常に良いああ、。情報のために、私はあなたのチケットでその答えを取った:https://stackoverflow.com/a/39234370/3581620 – Claudio

1

私は私のアプリで

ソリューションTwitterのログインを統合しようとしていたとき、私はこのエラーを取得する:あなたは、Twitterの開発者アカウントでアプリを作成すると、その時のコールバックURLフィールドがしたいと考えていません

1. を空の。 この問題がこの問題を解決するためにこのフィールドが空である場合は、このコールバックURLフィールドを空にしないでください。

  1. このエラーは、TwitterのコンシューマキーまたはTwitterの秘密キーが一致しない場合に発生することがあります。 両方のシナリオにチェックを入れてください。

ハッピーコーディング.... !!!

0
AppDelegate: 
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

     TWTRTwitter.sharedInstance().start(withConsumerKey:"xxxx", consumerSecret:"xxxxxxxxxxx") 
      return true 
     } 

     func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { 
      return TWTRTwitter.sharedInstance().application(app, open: url, options: options) 
     } 

    ViewController 

     @IBAction func twitterClick(_ sender: Any) { 
      // Swift 
      let composer = TWTRComposer() 

      composer.setText("just setting up my Twitter Kit") 
      composer.setImage(UIImage(named: "twitterkit")) 

      // Called from a UIViewController 
      composer.show(from: self.navigationController!) { (result) in 
       if (result == .done) { 
       print("Successfully composed Tweet") 
       } else { 
       print("Cancelled composing") 
       } 
      } 
     } 

     @IBAction func logOutUserTwitter(_ sender: Any) { 
      // Swift 
      let store = TWTRTwitter.sharedInstance().sessionStore 

      if let userID = store.session()?.userID { 
       store.logOutUserID(userID) 
      } 
     } 

Info.plist 
<key>CFBundleURLTypes</key> 
<array> 
    <dict> 
    <key>CFBundleURLSchemes</key> 
    <array> 
     <string>twitterkit-<xxxx></string> 
    </array> 
    </dict> 
</array> 
<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>twitter</string> 
    <string>twitterauth</string> 
</array> 

Settings Twitter page develop: 
Callback URL enter http://localhost 

https://github.com/twitter/twitter-kit-ios/wiki/Installation

関連する問題