-1

I created a C# programm which searches movie details with the title of the movie. I create the link:

        string link = "https://itunes.apple.com/search?";

        link += "term=";

        string cTitle = Titel.Replace(" ", "+");
        link += cTitle;

        link += "&country=DE";
        link += "&media=movie";
        link += "&entity=movie";
        link += "&attribute=movieTerm";
        link += "&limit=1";

with the movie title "Bus 657" that would be the following link:

https://itunes.apple.com/search?term=Bus+657&country=DE&media=movie&entity=movie&attribute=movieTerm&limit=1

If I open that link I get a txt file with the result I need. But if I get that in c# with the following code:

WebClient client = new WebClient();
var json = client.DownloadString(link);
Thread.Sleep(3100);

I get 0 results. Can someone help me to fix that?

I have a lot movie titles which title are named by the original iTunes title of the store at germany.

Thx :)

moxmlb
  • 1,190
  • 3
  • 10
  • 18
  • That text file contains zero results. –  Aug 22 '17 at 13:02
  • With the link I posted? My text file shows 1 result – moxmlb Aug 22 '17 at 13:03
  • `{ "resultCount":0, "results": [] }` –  Aug 22 '17 at 13:04
  • I get that file: { "resultCount":1, "results": [ {"wrapperType":"track", "kind":"feature-movie", "trackId":1059063782, "artistName":"Scott Mann", "trackName":"Bus 657", "trackCensoredName":"Bus 657", (...) ] – moxmlb Aug 22 '17 at 13:05
  • i get a result from the link - { "resultCount":1, "results": [ {" – ajg Aug 22 '17 at 13:05
  • i tried the link too and it does give me one result (i am located in Germany). Could it be some itunes API logic using client (browser) information? I don't know how WebClient identifies itself to the webserver, compared to a regular browser. Maybe check both requests with fiddler and add needed headers to your WebClient request. – Dirk Trilsbeek Aug 22 '17 at 13:05
  • I only get at some titles no result, I worked with 780 titles and 700 had a result and 80 not. and the Bus 657 is one of them. And I named it like the title you see at iTunes – moxmlb Aug 22 '17 at 13:07
  • `Titel.Replace(" ", "+");` should be replaced with https://msdn.microsoft.com/en-us/library/zttxte6w%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 – mjwills Aug 22 '17 at 13:16

2 Answers2

1

Add the User Agent to the request header and try.

WebClient client = new WebClient();
client.Headers.Add("user-agent","Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
var json = client.DownloadString(link);

I received "resultCount":1

Koopakiller
  • 2,838
  • 3
  • 32
  • 47
ザヘド
  • 614
  • 1
  • 6
  • 17
  • That worked for the Bus 657 problem, but the other movies have no results – moxmlb Aug 22 '17 at 13:25
  • @MMbach Can you share another title you're facing issue with? – ザヘド Aug 22 '17 at 13:36
  • I think the title is correct, I have the same problem for other titles – moxmlb Aug 22 '17 at 13:37
  • This link works too: `https://itunes.apple.com/de/search?term=bus+657&media=movie&entity=movie&attribute=movieTerm&limit=1`. I removed the country from QueryString. Try this and see if it works for other movie titles. Also use lowercase **de** instead of DE. – ザヘド Aug 22 '17 at 14:00
0

Your link is wrong.

You have:

                                        BZZZZT - should be %20
                                        ↓
https://itunes.apple.com/search?term=Bus+657&country=DE&media=movie&entity=movie&attribute=movieTerm&limit=1

Your movie title is "Bus 657". That space should be encoded as %20, not a +. Your link should be:

https://itunes.apple.com/search?term=Bus%20657&country=DE&media=movie&entity=movie&attribute=movieTerm&limit=1

With the corrected link, you get results. You should be using HttpServerUtility.UrlEncode or some other function to properly URL encode your URL. Or build your URL using the UriBuilder class.