I want to like video of YouTube.
I have acquired AUTH_TOKEN using AccountManager
using the following
am.getAuthToken(mAccount, AUTH_TOKEN_TYPE, null, this, new AccountManagerCallback<Bundle>()
{
public void run(AccountManagerFuture<Bundle> future)
{
try
{
if(future != null && future.getResult() != null)
{ if(future.getResult().containsKey(AccountManager.KEY_AUTHTOKEN))
{
AUTH_TOKEN = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
}
}
}
catch(OperationCanceledException e)
{ }
catch(AuthenticatorException e)
{ }
catch(IOException e)
{ }
catch(Exception e)
{ }
}
}, null);
Now i want to like(Rate) the video
developers.google.com- Videos: rate explains how to rate a video
but i am unaware that how can i use my CLIENT_ID, REDIRECT_URI, CLIENT_SECRET generated from Google APIs Console.
I generated this uri
String uri ="https://www.googleapis.com/youtube/v3/videos/rate?id="+ TEST_VIDEO_ID + "&rating=like&mine=true&access_token="+AUTH_TOKEN + "&key=" + DEVELOPER_KEY;
Is this uri wrong how can i use https://www.googleapis.com/youtube/v3/videos/rate?
with Google API console's Constants
I am using this uri string using the following method which is not responding right result as specified on developer.google.com I was using this method to get the response(like list of video, playlist etc) from youtube but i think this will not work or working in this case
Please help!!!!
private JSONObject getResponse(String apiUrl)
{
try
{
HttpClient client = new DefaultHttpClient();
HttpUriRequest request = new HttpGet(apiUrl);
HttpResponse response = client.execute(request);
String jsonString = StreamUtils.convertToString(response.getEntity().getContent());
JSONObject mJson = new JSONObject(jsonString);
return mJson;
}
catch(ClientProtocolException e)
{}
catch(Exception e)
{}
return null;
}
Thanks in advance.
I would suggest you to use Google API Java client library and YouTube Service.
Examples here and Android sample project.
If not you can generate sample requests from API explorer.
In your request, set the access_token as authorization header.
来源:https://stackoverflow.com/questions/18856551/like-video-with-access-token-on-youtube-using-youtube-data-api-v3