Youtube Subscribe Button Implementation

Youtube Subscribe Button

Implementation Button Subcribe Youtube with Google API.

Youtube Subscribe Button

Requirements

  • Java 1.8

Gradle

Add the following to your build.gradle to use:

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.SWRevo:YtbSubscribeButton:1.1.1'
}

To create credentials for YouTube API access, we create a variable :

private GoogleAccountCredential mCredential;

Next, add the method below to your activity's onCreate.

mCredential = GoogleAccountCredential.usingOAuth2(
    getApplicationContext(), Collections.singletonList(YouTubeScopes.YOUTUBE))
    .setBackOff(new ExponentialBackOff()
);

Tambahkan motode memanggil API Youtube Subscribe di Button

SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PREF_ACCOUNT_NAME, emailId);
editor.apply();
getResultsFromApi();

Dan berikut ini adalah listener untuk subcribe Youtube

private void getResultsFromApi() {
    if (! isGooglePlayServicesAvailable()){
        acquireGooglePlayServices();
    } else if (mCredential.getSelectedAccountName() == null){
        chooseAccount();
    } else {
        pDialog = new ProgressDialog(YouTubeSubscribeActivity.this);
        pDialog.setMessage("Please wait...");
        pDialog.show();
        // handing subscribe task by presenter
        presenter.subscribeToYouTubeChannel(mCredential,"UC_x5XG1OV2P6uZZ5FSM9Ttw");
        // pass youtube channelId as second parameter
    }
}
Complete explanation of how to make a Google Sheets backend
Comments are closed.