[英]Twitter4J Creating Callback URL That Goes Back To My App
I've read through this: Android: Login with Twitter using Twitter4J 我已阅读以下内容: Android:使用Twitter4J使用Twitter登录
And the selected answer doesn't make sense in the context that I need it. 在我需要的上下文中,选择的答案没有任何意义。
I want the user to be able to login to their Twitter account from our app, and then, once they've logged in, I want our app to reload. 我希望用户能够从我们的应用程序登录其Twitter帐户,然后,一旦他们登录,我希望重新加载我们的应用程序。
It loads the twitter webpage (although I wish they could just login within my app instead of needing the browser) but then I'm not sure how to set 'my application' as the callback. 它加载了twitter网页(尽管我希望他们可以只在我的应用程序中登录而不需要浏览器),但是然后我不确定如何将“我的应用程序”设置为回调。
Can you advise where I can find (or set if it doesnt exist) the callback URL so when the user logs into Twitter it our app re-opens? 您能建议我在哪里可以找到(或设置它是否不存在)回调URL,以便当用户登录Twitter时,我们的应用程序重新打开吗?
This is my login code: 这是我的登录代码:
public void loginUser()
{
//Check if already logged in
if (!isTwitterLoggedInAlready()) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance();
try {
//What do I set my TWITTER_CALLBACK_URL as?
requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
} catch (TwitterException e) {
e.printStackTrace();
}
} else {
// user already logged into twitter
Toast.makeText(getApplicationContext(),
"Already Logged into twitter", Toast.LENGTH_LONG).show();
}
}
I couldnt quite figure out how the intents-in-manifest business worked. 我无法弄清楚清单中的意图是如何工作的。
Instead I did the following (and it works) 相反,我做了以下工作(并且有效)
Created a WebViewClient and overrided its shouldOverrideUrlLoading 创建了一个WebViewClient并覆盖了它的shouldOverrideUrlLoading
Set this WebViewClient to the webview and load the twitter login from there. 将此WebViewClient设置为webview并从那里加载twitter登录。
In my WebView client I am parsing the twitter response looking for my string (which can be anything). 在我的WebView客户端中,我正在解析Twitter响应以查找我的字符串(可以是任何字符串)。 If its there, I hide the webview.
如果存在,我将隐藏Webview。
@Override public boolean shouldOverrideUrlLoading (WebView view, String url) { Log.d("Loading webview", url); if (url.contains(TwitterActivity.CALLBACK_URL)) { Uri uri = Uri.parse(url); String oauthVerifier = uri.getQueryParameter("oauth_verifier"); _twitterActivty.closeTwitterBrowser(oauthVerifier); return false; } view.loadUrl(url); return true; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.