【问题标题】:How to pass auth token from Parse SDK to Fabric TwitterKit?如何将身份验证令牌从 Parse SDK 传递到 Fabric TwitterKit?
【发布时间】:2015-09-13 04:44:45
【问题描述】:

我使用 Parse SDK 中的 +[PFTwitterUtils loginWithBlock:] 方法登录我的 Twitter 用户。为了获取用户个人资料图片,我使用 Fabric TwitterKit 中的 -[Twitter logInWithCompletion:] 方法第二次登录。有没有办法将身份验证令牌从 Parse SDK 传递到 TwitterKit 并且只登录一次

有一种方法可以使用 Parse SDK 中的 PF_Twitter 类从 Parse 导出身份验证令牌和身份验证令牌秘密。看起来应该可以使用 -[TWTRSession initWithSessionDictionary:] 创建 TwitterKit 会话,但 Twitter docs 没有说明字典格式,我无法让它工作。

【问题讨论】:

    标签: ios twitter parse-platform pfuser


    【解决方案1】:

    解析

    当用户使用 Parse 的 TwitterUtils 登录时,您会得到这个名为 twitter 的方法。现在我正在使用 Swift,所以使用PFTwitterUtils.twitter(),您将获得所需的所有数据。我想它应该是 Objective-C 中的[PFTwitterUtils twitter];

    Parse 上的课程是 PF_Twitter

    Fabric TwitterKit

    获得该对象后,您将可以访问当前用户的authTokenauthTokenSecret。 然后你必须使用 TwitterKit 中的这个方法(注意:这将在未来被弃用,查看底部的 UPDATE):

    目标-C:

    [Twitter sharedInstance]

    logInWithExistingAuthToken:authTokenSecret:completion:

    斯威夫特:

    Twitter.sharedInstance().logInWithExistingAuthToken(authToken, authTokenSecret: authTokenSecret, completion: { (session, error) -> Void in
    })
    

    如果一切顺利,这将返回当前会话。

    文档:

    解析:

    https://parse.com/docs/ios/api/Classes/PFTwitterUtils.html#//api/name/twitter

    PF_Twitter - https://parse.com/docs/ios/api/Classes/PF_Twitter.html

    面料:

    https://docs.fabric.io/appledocs/Twitter/Classes/Twitter.html#//api/name/logInWithExistingAuthToken:authTokenSecret:completion:

    更新

    我刚刚注意到logInWithExistingAuthToken 将被弃用。所以最好的方法是使用TWTRSessionStoresaveSessionWithAuthToken方法:

    Twitter.sharedInstance().sessionStore.saveSessionWithAuthToken(authToken, authTokenSecret: authTokenSecret, completion: { (session, error) -> Void in
    
                        })
    

    【讨论】:

    • 非常适合我。这应该被接受为正确答案。
    猜你喜欢
    • 2020-05-21
    • 2021-08-17
    • 2021-04-13
    • 2020-04-10
    • 2011-02-06
    • 2015-02-24
    • 2019-06-16
    • 1970-01-01
    • 2014-02-01
    相关资源
    最近更新 更多