Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:23:45+00:00 2026-06-13T11:23:45+00:00

I am trying to use the Youtube GDATA API in order to add a

  • 0

I am trying to use the Youtube GDATA API in order to add a new playlist to a youtube account.
I base my code on the documentation: https://developers.google.com/youtube/2.0/developers_guide_protocol_playlists#Adding_a_playlist

I first get an access token and use my developer key appropriately.
The post seems to work just fine, but when trying to get back the response, I get a file not found exception while calling getInputStream.

Does anyone has an idea?
Thanks

Here is the connection code (an updated cleaner version):

@Override
protected Boolean doInBackground(Void... arg0) {
    BufferedReader input = null;
    InputStreamReader inputStreamReader = null;
    StringBuilder postContentXml = new StringBuilder();

    postContentXml.append("<?xml version='1.0' encoding='UTF-8'?>").
        append("<entry xmlns='http://www.w3.org/2005/Atom'") .
        append(" xmlns:yt='http://gdata.youtube.com/schemas/2007'>").
        append("<title type='text'>Sports Highlights Playlist</title>").
        append("<summary>A selection of sports highlights</summary>").
        append("</entry>");

    byte[] buffer = postContentXml.toString().getBytes();
    StringBuilder response = new StringBuilder();

    try {
        URL url = new URL("https://gdata.youtube.com/feeds/api/users/default/playlists");
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

        // Initialize connection parameters
        urlConnection.setConnectTimeout(30000);
        urlConnection.setReadTimeout(30000);
        urlConnection.setDoOutput(true);
        urlConnection.setRequestMethod("POST");

        // Headers initialization
        urlConnection.setRequestProperty("Content-Type", "application/atom+xml");
        urlConnection.setRequestProperty("Content-Length", String.valueOf(buffer.length));
        urlConnection.setRequestProperty("Authorization", mAuthToken);
        urlConnection.setRequestProperty("GData-Version", "2");
        urlConnection.setRequestProperty("X-GData-Key", YoutubeUtils.getDevKey());

        OutputStream os = urlConnection.getOutputStream();
        os.write(buffer, 0, buffer.length);
        os.flush();
        os.close();

        InputStream inputStream = urlConnection.getInputStream();

        inputStreamReader = new InputStreamReader(inputStream, "UTF-8");


        input = new BufferedReader(inputStreamReader, 4096);

        String strLine = null;
        while ((strLine = input.readLine()) != null) {
            response.append(strLine);
        }

        input.close();
        inputStreamReader.close();
        inputStream.close();
        urlConnection.disconnect();

        Log.d("CreatePlaylistTask", "Response: " + response);
    }
    catch(Exception e) {
        Log.d("CreatePlaylistTask", "Error occured: " + e.getMessage());
    }

    return true;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:23:46+00:00Added an answer on June 13, 2026 at 11:23 am

    I’m assuming that the POST wasn’t actually successful.

    If I had to guess from looking at your code, I’d think that the problem might be the Authorization header value. What does myAuthToken look like, and what type of token is it? If it’s an OAuth 2 token, for instance, then the value needs to be Bearer TOKEN_VALUE, not just TOKEN_VALUE.

    Also, please note that v3 of the YouTube Data API will be released in the near future, and it will offer better support on Android using the new Google APIs Client Library for Java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Youtube's new video embed code, which detects via the iframe
Is there a definitive gem for the YouTube API? I'm trying to use youtube_g,
Okay so what i am trying to achieve is use the youtube api to
I'm trying to use youtube's api to bring back a listing of a user's
I am trying to use the youtube API to pulldown some videos for my
I'm trying to use the Youtube Iframe API inside a module definded with Require
I'm trying to use youtube's data api to search where the search term includes
I'm trying to use YouTube API v2.0 to let users authenticate into their YouTube
I am trying to use the YouTube API to detect when a video ends
I'm trying to use the youtube javascript player api to embed youtube videos into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.