unity3d - Get List of Youtube channels subscribe by current user in android? -
hello want list of channels subscribe current user in android.
steps follow:
1) https://developers.google.com/youtube/v3/docs/subscriptions/list
by read description, created api key android , oauth key in google developer console , tired implement following request
get https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&mine=true&key={your_api_key}. can see have set part = snippet
, mine = true
.
for authentication followed https://developer.android.com/training/id-auth/authenticate.html
here code
accountmanager = accountmanager.get(this); bundle options = new bundle(); am.getauthtoken( myaccount_, // account retrieved using getaccountsbytype() "manage tasks", // auth scope options, // authenticator-specific options this, // activity new ontokenacquired(), // callback called when token acquired new handler(new onerror())); // callback called if error occurs
after adding proper permission can account in myaccount_
on call backbaack of tokenacquire
private class ontokenacquired implements accountmanagercallback<bundle> { @override public void run(accountmanagerfuture<bundle> result) { // result of operation accountmanagerfuture. bundle bundle = result.getresult(); // token named value in bundle. name of value // stored in constant accountmanager.key_authtoken. token = bundle.getstring(accountmanager.key_authtoken); ... } }
i not getting token value.
please guide me. is there alternative approach or if have update/modify something?
my permission in xml are
<uses-permission android:name="android.permission.account_manager" /> <uses-permission android:name="android.permission.get_accounts" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.use_credentials" />
i getting error @ line token = bundle.getstring(accountmanager.key_authtoken);
in catch of exception handling.
android.accounts.authenticatorexception. attempt invoke virtual method 'java.lang.string android.os.bundle.getstring(java.lang.string)' on null object reference
i using android 6.0 , require run time permission.
to access token according obtain access token, think need use valid scope 'https://gdata.youtube.com'
youtube api. however, looking @ code, seems passed "manage tasks" auth scope. try setting 'https://gdata.youtube.com'
instead.
with regard getting number of subscribers, try making rest call in android following uri request:
get https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&mysubscribers=true&fields=pageinfo&key={server_api_key}
it returns json response totalresults represents number of subscribers:
{ "pageinfo": { "totalresults": 2, "resultsperpage": 5 } }
Comments
Post a Comment