Like video with access token on YouTube using YouTube Data API v3?
Asked Answered
C

2

2

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.

Cessation answered 17/9, 2013 at 17:49 Comment(1)
Did You find any solution for rating a Youtube Video using V3Roentgenology
E
2

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.

Erse answered 19/9, 2013 at 19:21 Comment(0)
W
0

In your request, set the access_token as authorization header.

Wadsworth answered 4/11, 2013 at 5:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.