Giter VIP home page Giter VIP logo

twitteroauthview's Introduction

TwitterOAuthView

Overview

A WebView subclass dedicated to Twitter OAuth on Android, using twitter4j.

As this class is implemented as a subclass of View, it can be integrated into the Android layout system seamlessly. This fact makes this class an easily-reusable UI component.

To use this class, it is not necessary to review the flow of OAuth handshake. Just implement TwitterOAuthView.Listener and call start() method. The result of OAuth handshake is reported via either of the listener's methods, onSuccess() or onFailure().

License

Apache License, Version 2.0

Download

git clone git://github.com/TakahikoKawasaki/TwitterOAuthView.git

Javadoc

TwitterOAuthView API

Example

package twitteroauthview.sample;


import twitter4j.auth.AccessToken;
import com.neovisionaries.android.twitter.TwitterOAuthView;
import com.neovisionaries.android.twitter.TwitterOAuthView.Result;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;


/**
 * An example Activity implementation using {@link TwitterOAuthView}.
 *
 * @author Takahiko Kawasaki
 */
public class TwitterOAuthActivity extends Activity implements TwitterOAuthView.Listener
{
    // Replace values of the parameters below with your own.
    private static final String CONSUMER_KEY = "YOUR CONSUMER KEY HERE";
    private static final String CONSUMER_SECRET = "YOUR CONSUMER SECRET HERE";
    private static final String CALLBACK_URL = "YOUR CALLBACK URL HERE";
    private static final boolean DUMMY_CALLBACK_URL = true;


    private TwitterOAuthView view;
    private boolean oauthStarted;


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // Create an instance of TwitterOAuthView.
        view = new TwitterOAuthView(this);

        setContentView(view);

        oauthStarted = false;
    }


    @Override
    protected void onResume()
    {
        super.onResume();

        if (oauthStarted)
        {
            return;
        }

        oauthStarted = true;

        // Start Twitter OAuth process. Its result will be notified via
        // TwitterOAuthView.Listener interface.
        view.start(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL, DUMMY_CALLBACK_URL, this);
    }


    public void onSuccess(TwitterOAuthView view, AccessToken accessToken)
    {
        // The application has been authorized and an access token
        // has been obtained successfully. Save the access token
        // for later use.
        showMessage("Authorized by " + accessToken.getScreenName());
    }


    public void onFailure(TwitterOAuthView view, Result result)
    {
        // Failed to get an access token.
        showMessage("Failed due to " + result);
    }


    private void showMessage(String message)
    {
        // Show a popup message.
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
}

See Also

Author

Takahiko Kawasaki, Neo Visionaries Inc.

twitteroauthview's People

Contributors

atermenji avatar

Watchers

UnsafePointer<T> avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.