2

我使用 Twitter 的官方指南进行登录

我的步骤:

  1. 应用程序管理中的回调 URL将字段留空

  2. 安装吊舱pod 'Fabric'pod 'TwitterKit'

  3. 添加Info.plist
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>twitterkit-xxxxxxxx</string>
            <string>fbxxxxxxxx</string>
        </array>             
    </dict>
</array>
<key>FacebookAppID</key>
<string>xxxxx</string>
<key>FacebookDisplayName</key>
<string>Name</string>    
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>twitter</string>
    <string>twitterauth</string>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>
<key>Fabric</key>
<dict>
  <key>APIKey</key>
  <string>xxxxxxxxxx</string>         
  <key>Kits</key>
  <array>
      <dict>
          <key>KitInfo</key>
          <dict/>
          <key>KitName</key>
          <string>Crashlytics</string> 
     </dict>
</array>
</dict>
  1. 添加在class AppDelegate

    import TwitterKit
    ....
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        ....
        Twitter.sharedInstance().start(withConsumerKey:"xxxxxx", consumerSecret:"xxxxx") 
    }
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {    
        return Twitter.sharedInstance().application(app, open: url, options: options)
    }
    
  2. 添加框架: 在此处输入图像描述

  3. 添加在Header.h #import <TwitterKit/TwitterKit.h>

  4. 从官方指南添加TwitterLogInButton

当我单击按钮登录时,出现错误(测试是在模拟器 iOS 9.3 上进行的):

-canOpenURL: failed for URL: "twitterauth://authorize?consumer_key=xxxSAMExxx&consumer_secret=yyyyyyy&oauth_callback=twitterkit-xxxSAMExxx" - error: "(null)"
[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>
}
4

1 回答 1

1

您需要将 CFBundleURLSchemes 条目分开,如下所示:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fbXXX</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>twitterkit-XXX</string>
        </array>
    </dict>
</array>

您可能还想从官方 Twitter 文档中介绍的 Fabric 迁移

于 2017-07-27T23:51:14.683 回答