0

I'm trying to build a URL using a uri Builder and extract data out of a json file using Volley from a differemt Endpoint. My Url looks like this //http://api.themoviedb.org/3/movie/157336/videos?api_key=###. I'm not sure if im doing it properl because i'm getting a bad request 400 so i suspect that there is something i'm missing.

 Intent intent = getIntent();
    String movieId = intent.getStringExtra(Constants.MOVIE_ID);
    Uri.Builder builder = new Uri.Builder();
    builder.scheme("http")
            .authority("api.themoviedb.org/3/movies/")
            .appendPath(movieId)
            .appendPath("videos")
            .appendQueryParameter("api_key", BuildConfig.ApiKey);

    String myUrl = builder.build().toString();
Zoe
  • 27,060
  • 21
  • 118
  • 148

1 Answers1

0

There are multiple errors with your url, but only one specifically with the way you build it. The Authority should be without any path segments, these should be addded with the append Path, because the / will get encoded and you end with this url: https://api.themoviedb.org%2F3%2Fmovies%2F/157336/videos?api_key=###

So just divide this part into the following:

.authority("api.themoviedb.org")
.appendPath("3")
.appendPath("movies")

Then there are some specifics with tmdb firstly you can only call their api over https, so set this as the scheme:

builder.scheme("https")

Then you are trying to reach a undefined endpoint, if you have a look at the documentation under https://developers.themoviedb.org/3/movies/get-movie-videos you will notice that you are currently trying to reach

/movies/{id}/videos

but the endpoint is at:

/movie/{id}/videos

So change the:

.appendPath("movies")

with .appendPath("movie")

now if you Log out your myUrl variable you should see the following url:

https://api.themoviedb.org/3/movie/157336/videos?api_key=###

which is the correct one.

glm9637
  • 894
  • 9
  • 20
  • Sorry for the late reply, I've been away. I've change it and worked fine, thank you. And once again, sorry for the late reply. – StanleyManoah Apr 08 '19 at 16:37