1

저는 YouTube Data API를 사용하여 YouTube 검색을 표시하는 Xamarin에 페이지를 작성하고 있습니다. 그것은 잘 컴파일하지만 안드로이드 장치에서 실행하면 잠시 후 잠시 응답하지 않기 때문에 응용 프로그램을 종료하라는 메시지가 나타납니다. 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를 사용하는 가정입니다 :

난 그냥 당신이 (403) 또는 다른 액세스/인증 오류 받고되지 않도록하기 위해 시도/잡기에 전체 루틴을 포장하려고 할 것
Google.Apis.YouTube.v3" version="1.16.0.582" 

:

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()에 대한 이벤트 처리기를 다른 메서드가 있습니다. –