1

私はXamarinにYouTube Data APIを使用してYouTube検索を表示するページを作成しています。それはうまくコンパイルされますが、Androidデバイスで実行すると、アプリケーションが応答しないため、アプリケーションを終了するように暫定的にプロンプ​​トが表示されます。私は、YouTubeServiceオブジェクトを確立することと関係があると思います。asyncタスクのタイムアウト

これは基本的にも、こっちのスレッドで操作を実行しているように見えるスタックトレースがある

private async Task Run() 
    { 
     videoList.Clear(); 

     var youtubeService = new YouTubeService(new BaseClientService.Initializer() 
     { 
      ApiKey = DEVELOPER_KEY, 
      ApplicationName = "Xamarin-Basics" 
     }); 

     var searchListRequest = youtubeService.Search.List("snippet"); 
     searchListRequest.Q = "mkbhd"; 
     searchListRequest.MaxResults = 50; 

     var searchListResponse = await searchListRequest.ExecuteAsync(); 

     foreach(var searchResult in searchListResponse.Items) 
     { 
      if (searchResult.Id.Kind.Equals("youtube#video")) 
      { 
       videoList.Add(new VideoInfo(searchResult.Snippet.Title, searchResult.Snippet.Description)); 
      } 
     } 
    } 

リストビューにデータAPIとロード与えられた検索語のためのビデオの50を呼び出し、再度:

09-15 20:31:21.352 D/Mono (6831): Assembly Ref addref  Newtonsoft.Json[0xb72c8210] -> System.Linq.Expressions[0xb72e98a0]: 3 
Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External] 
09-15 20:31:21.562 D/Mono (6831): Assembly Ref addref  Google.Apis.YouTube.v3[0xb72c7310] -> Newtonsoft.Json[0xb72c8210]: 4 
09-15 20:31:22.127 D/Mono (6831): DllImport searching in: '__Internal'  ('(null)'). 
09-15 20:31:22.127 D/Mono (6831): Searching for 'CloseZStream'. 
09-15 20:31:22.127 D/Mono (6831): Probing 'CloseZStream'. 
09-15 20:31:22.127 D/Mono (6831): Found as 'CloseZStream'. 
09-15 20:31:31.950 D/Mono (6831): [0xb76fa5b0] worker finishing 
Thread finished: <Thread Pool> #3 
The thread 'Unknown' (0x3) has exited with code 0 (0x0). 
09-15 20:31:57.148 D/Mono (6831): [0xb808e9b8] worker finishing 
Thread finished: <Thread Pool> #7 
The thread 'Unknown' (0x7) has exited with code 0 (0x0). 
09-15 20:32:04.446 D/Mono (6831): [0xb77219d8] worker finishing 
Thread finished: <Thread Pool> #4 
The thread 'Unknown' (0x4) has exited with code 0 (0x0). 
Thread finished: <Thread Pool> #2 
The thread 'Unknown' (0x2) has exited with code 0 (0x0). 
09-15 20:32:49.051 D/Mono (6831): [0xb808de40] worker finishing 
Thread finished: <Thread Pool> #8 
The thread 'Unknown' (0x8) has exited with code 0 (0x0). 
Thread started: <Thread Pool> #11 
Thread started: <Thread Pool> #12 
09-15 20:32:59.725 D/Mono (6831): [0xb81d8738] worker starting 
09-15 20:33:30.573 D/Mono (6831): [0xb81d8738] worker finishing 
Thread finished: <Thread Pool> #12 
The thread 'Unknown' (0xc) has exited with code 0 (0x0). 
09-15 20:33:46.394 D/Mono (6831): [0xb80a4790] worker finishing 
Thread finished: <Thread Pool> #9 
The thread 'Unknown' (0x9) has exited with code 0 (0x0). 
Thread finished: <Thread Pool> #11 
The thread 'Unknown' (0xb) has exited with code 0 (0x0). 
Thread started: <Thread Pool> #13 
Thread started: <Thread Pool> #14 
09-15 20:34:39.731 D/Mono (6831): [0xb81d8738] worker starting 
Thread started: <Thread Pool> #15 
09-15 20:34:39.749 D/Mono (6831): [0xb84d0f60] worker starting 
09-15 20:34:52.494 D/Mono (6831): [0xb84d0f60] worker finishing 
Thread finished: <Thread Pool> #15 
The thread 'Unknown' (0xf) has exited with code 0 (0x0). 
+0

あなたはユーチューブのDLLのバージョンがありますか? – DaImTo

+0

バージョン3は私が持っているものです –

答えて

0

あなたのコードは基本的に正しいと思われます。私はあなたが最新のv3 APIを使用していると仮定しています:

Google.Apis.YouTube.v3" version="1.16.0.582" 

私はちょうどあなたが403または他のアクセス/認証エラーを取得していないことを確認するのtry/catchで全体のルーチンをラップしようとするだろう:

Xamarin.Android例:

try 
{ 
    var youtubeService = new YouTubeService(new BaseClientService.Initializer() 
    { 
     ApiKey = DEVELOPER_KEY, 
     ApplicationName = "com.sushihangover.youtubeapi", 
    }); 
    var searchListRequest = youtubeService.Search.List("snippet"); 
    searchListRequest.Q = "StackOverflow"; 
    searchListRequest.MaxResults = 50; 

    var searchListResponse = await searchListRequest.ExecuteAsync(); 

    foreach (var searchResult in searchListResponse.Items) 
    { 
     if (searchResult.Id.Kind.Equals("youtube#video")) 
     { 
      Console.WriteLine(searchResult.Snippet.Title); 
     } 
    } 
} 
catch (Exception ex) 
{ 
    Console.WriteLine(ex.Message); 
} 
+0

私はそれを試みましたが、それは何も捕まえませんでした。それが実行されたままになり、ループしていました、私は上記のスタックトレースを掲示しました。 –

+1

'var searchListRequest ...'にブレークポイントを設定した場合、それはそこに到達しますか? 'Run'メソッドはどうやって呼びますか? – SushiHangover

+0

そこには到着しますが、決してそこを過ぎることはありません。 foreachループに到達することはありません。私は、ボタンのクリックのためのイベントハンドラである別のメソッドを持って、内部はRun()です。 –

関連する問題