twitter-archive / twitter-kit-ios

Twitter Kit is a native SDK to include Twitter content inside mobile apps.
Apache License 2.0
690 stars 448 forks source link

在推特授权应用中心中取消对应用的授权,该应用无法再次获取推特的授权 #69

Closed zhipengbird closed 6 years ago

zhipengbird commented 6 years ago

按照正常的开发流程,应用可以正常的调用推特的授权界面,授权并进行分享操作。 但是在推特授权应用中心列表中取消对该应用的授权后,应用分享失败。控制名打出如下提示信息 [TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?><errors><error code="415">Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings</error></errors>" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?><errors><error code="415">Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings</error></errors>} 我做了以下尝试: 查看当前用户 [[Twitter sharedInstance].sessionStore hasLoggedInUsers] 该方法返回有用户登录,但是分享失败。 然后我接着尝试以下方法:

  1. 退出当前登录的用户
    for (TWTRSession * Session in [Twitter sharedInstance].sessionStore.existingUserSessions) {
        [[Twitter sharedInstance].sessionStore logOutUserID:Session.userID];
    }
  2. 重新调用login方未能进行登录
      [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {
                if (session) {
    //分享操作
                } else {
    //错误提示
                }
            }
        }];

    该登录方法不在弹出授权界面,也不会弹出登录页,等待几秒后,返回上述的错误信息。 以上问题是在没有twitter客户端的情况下出现的,有客户端情况下可以正常授权。 以上方式均无法正常获取授权。请各位开发人员帮忙解决。 在取消授权后,再次调用登录方法应可以再试打开授权页进行授权操作。 PS:在示例中,判断当前是否有登录用户,有则可以进行分享,该逻辑存在漏洞,如果用户授权失败或在twitter中取消对该应用的授权,后续操作都会失败,这里应该加上一个授权是否有效的检测。 @garru @mgadda @baroquebobcat @niw @amro please help me, thank you!

zhipengbird commented 6 years ago

@garru @mgadda @baroquebobcat @niw @amro please help me, thank you!

shaharukhs commented 6 years ago

I have same issue I am using following pod

TwitterCore (3.1.0)
TwitterKit (3.3.0)

When I call

TWTRTwitter.sharedInstance().logIn(completion: { (session, error) in
     if (session != nil) {
          print("signed in as \(String(describing: session?.userID))")
     } else {
           print("error: \(String(describing: error?.localizedDescription))")
     }
})

Get following error

[TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?>Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings} error: Optional("Request failed: forbidden (403)")

zegnaro commented 6 years ago

Facing similar issue. Wonder if anyone has found a solution yet?

jslz commented 6 years ago

Having the same problem here. (From what little I can tell, I don't think it is the logIn() call where it dies, I currently think it might be [[Twitter sharedInstance] startWithConsumerKey:consumerKey consumerSecret:consumerSecret], maybe. Basically in our app we never even get a Twitter UI to show up where anybody could even try to login, we get the 415 error first.)

For Android it seemed to become unblocked when I added another "callback URL" on our app's dashboard on apps.twitter.com, as "twittersdk://".

But iOS is still busted. I tried adding another callback URL as "twitterkit://" since the URL Sschemes contains "twitterkit-", but that hasn't fixed it.

jslz commented 6 years ago

doing this: https://stackoverflow.com/a/50850233/8168867 fixed it for us for iOS just now, apparently.

zhipengbird commented 6 years ago

May be we can change the callbackURL to twitterkit-consumerkey://

shenyufei commented 5 years ago

@zhipengbird 请问您解决了吗,怎么判断用户取消授权,从而重新进行授权呢,我用 [[Twitter sharedInstance].sessionStore hasLoggedInUsers] 判断的话,就算取消授权,还是返回true