Ejemplo n.º 1
0
    /** {@inheritDoc} */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      // Edge case - start activity without twitter
      if (twitter == null) {
        finish();
        return;
      }

      SoomlaUtils.LogDebug(TAG, "onCreate");

      if (webView == null) {
        webView = new SoomlaTwitterWebView(this);
        webView.setWebViewClient(
            new WebViewClient() {
              @Override
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // See if the URL should be handled by the provider
                // only if it's a callback which was passed by the
                // provider
                if (url.startsWith(oauthCallbackURL)) {
                  Uri uri = Uri.parse(url);
                  completeVerify(uri);
                  return true;
                }
                return false;
              }
            });
      }

      // we should append additional param forcing login/pass request, otherwise app will be loaded
      // with previous account
      // decision based on https://dev.twitter.com/oauth/reference/get/oauth/authorize
      String url = getIntent().getStringExtra("url") + "&force_login=true";
      webView.loadUrlOnUiThread(url);
      webView.show(this);
    }
Ejemplo n.º 2
0
    private void completeVerify(Uri uri) {
      SoomlaUtils.LogDebug(TAG, "Verification complete");
      /** Handle OAuth Callback */
      if (uri != null && uri.toString().startsWith(oauthCallbackURL)) {
        String verifier = uri.getQueryParameter(OAUTH_VERIFIER);
        if (!TextUtils.isEmpty(verifier)) {
          twitter.getOAuthAccessTokenAsync(mainRequestToken, verifier);
        } else {
          // Without a verifier an Access Token cannot be received
          // happens when a user clicks "cancel"
          cancelLogin();
        }
      }

      webView.hide();
      finish();

      mFinishedVerifying = true;
    }