Giter Club home page Giter Club logo

youtube-auth's Introduction

youtube-auth

Android Module for Youtube Sign-In with Channel selection.

  1. Clone or download module.

  2. Import module into project: Android Studio -> File -> New -> Import module -> Select directory with source of downloaded module.

  3. Add module to dependencies in the app level build.gradle:

    compile project(':youtube-auth')
    
  4. Start Sign-In to Youtube:

   YoutubeAuthManager.getInstance(CLIENT_ID, CLIENT_SECRET).startSignIn(
                this /*activity or fragment*/,
                R.style.AppTheme_NoActionBar /*Theme Resource ID (optional)*/,
                R.string.app_name_youtube_auth /*String Resource ID (optional)*/,
                R.drawable.ic_close_24dp /*Icon Resource ID (optional)*/
        );
  1. Handle Sign-In result:
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case YoutubeAuthActivity.REQUEST_CODE:
                if (resultCode == Activity.RESULT_OK) {
                    //this is a token for using in requests to Youtube Data API
                    if (data != null && data.getExtras().containsKey(YoutubeAuthManager.KEY_SIGN_IN_RESULT_TOKEN)) {
                        mToken = data.getStringExtra(YoutubeAuthManager.KEY_SIGN_IN_RESULT_TOKEN);
                        Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    String errMessage = data != null ? data.getStringExtra(YoutubeAuthManager.KEY_SIGN_IN_RESULT_ERROR) : "Cancelled";
                    Toast.makeText(this, errMessage, Toast.LENGTH_SHORT).show();
                }
                break;
            default:
                super.onActivityResult(requestCode, resultCode, data);
        }

    }
  1. Sign-Out:
YoutubeTokenHelper.getInstance(CLIENT_ID, CLIENT_SECRET).signOut(
                getApplicationContext(),
                new YoutubeTokenHelper.ICallbacks() {
                    @Override
                    public void onSuccess(String accessToken) {
                        //do something
                    }

                    @Override
                    public void onFail(String errMessage) {
                        Toast.makeText(getApplicationContext(), errMessage, Toast.LENGTH_SHORT).show();
                    }
                }
        );

youtube-auth

youtube-auth's People

Contributors

dmitriy-chernysh avatar

Watchers

 avatar  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.