Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

android - Like video with access token on YouTube using YouTube Data API v3?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...