We are not using any specific Twitter client library. For the rest api, we are using Retrofit and OkHttp libraries, but OAuth is happening in a standard Android WebView. The Twitter code is actually quite old; it hasn’t been updated in a while:
Intent i = new Intent(this, OAuthHelperWebView.class);
i.putExtra(OAuthHelperWebView.INTENT_EXTRA_KEY_OAUTH_CALLBACK_URL, OAUTH_CALLBACK_URL);
i.putExtra(OAuthHelperWebView.INTENT_EXTRA_KEY_OAUTH_URL, oAuthUrl);
startActivityForResult(i, OAuthHelperWebView.REQUEST_CODE);
package sample;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.lang.reflect.InvocationTargetException;
import sample.R;
@SuppressLint("SetJavaScriptEnabled")
public class OAuthHelperWebView extends Activity {
static final public String INTENT_EXTRA_KEY_OAUTH_URL = "intent_extra_key_url";
static final public String INTENT_EXTRA_KEY_OAUTH_CALLBACK_URL = "intent_extra_key_oauth_url";
static final public String RESULT_INTENT_KEY_ERROR_MSG = "result_intent_key_error_msg";
static final public String RESULT_INTENT_KEY_CALLBACK_URL = "result_intent_key_callback_url";
static final public int RESULT_CODE_CANCELLED = 0;
static final public int RESULT_CODE_OK = 1;
static final public int RESULT_CODE_ERROR = 2;
static final public int REQUEST_CODE = 1000;
static final public String DEFAULT_OAUTH_CALLBACK_URL = "http://web_message";
private WebView mWebView = null;
private String oauthCallbackUrl = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
if (url.startsWith(oauthCallbackUrl)) {
Intent i = new Intent();
i.putExtra(RESULT_INTENT_KEY_CALLBACK_URL, url);
setResult(RESULT_CODE_OK, i);
finish();
} else {
super.onPageFinished(view, url);
}
}
});
Intent extras = getIntent();
oauthCallbackUrl = extras.getStringExtra(INTENT_EXTRA_KEY_OAUTH_CALLBACK_URL);
if (oauthCallbackUrl == null)
oauthCallbackUrl = DEFAULT_OAUTH_CALLBACK_URL;
String url = extras.getStringExtra(INTENT_EXTRA_KEY_URL);
if (url == null) {
Intent errorIntent = createErrorIntent("url missing");
setResult(RESULT_CODE_ERROR, errorIntent);
finish();
return;
} else {
mWebView.loadUrl(url);
}
}
@Override
protected void onResume() {
super.onResume();
callWebKitFunction("onResume");
}
@Override
protected void onPause() {
callWebKitFunction("onPause");
super.onPause();
}
@Override
public void onBackPressed() {
mWebView.stopLoading();
setResult(RESULT_CODE_CANCELLED);
finish();
}
private void callWebKitFunction(String function) {
try {
Class.forName("android.webkit.WebView")
.getMethod(function, (Class[]) null)
.invoke(this.mWebView, (Object[]) null);
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoClassDefFoundError | NoSuchMethodException e) {
e.printStackTrace();
}
}
private Intent createErrorIntent(String msg) {
Intent errorIntent = new Intent();
errorIntent.putExtra(RESULT_INTENT_KEY_ERROR_MSG, msg);
return errorIntent;
}
}
As for frequency, we are still getting more information, but we have been getting several reports a day from our users.