3

IP カメラからビデオを取得し、YouTube チャンネルにライブで送信する WPF アプリケーションを作成したいと考えています。私はすべての Web サイトを見回していますが、C# を使用して YouTube にビデオをライブ ストリーミングする方法の例はありません。Google のウェブサイトに例がありますが、PHP、Java、および Phyton で記述されていますが、このプログラミング言語を知らないため、API を使用できませんでした。

少し書いてみましたがうまくいきませんでした。Javaの例を見て書いた私のコードは次のとおりです。

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
          new ClientSecrets { ClientId = "MyClientId", ClientSecret = "MyClientSecret" },
          new[] { DriveService.Scope.Drive,
            DriveService.Scope.DriveFile },
          "My Youtube Channel Name",
          CancellationToken.None,
          new FileDataStore("Drive.Auth.Store")).Result;

        string devkey = "AIzaSyCbxm6g9orAw9PF3MkzTb_0PGbpD3Xo1Qg";
        string username = "MyYoutubeChannelEmailAdress";
        string password = "MyPassword";

        YouTubeRequestSettings youtubereqsetting = new YouTubeRequestSettings("API Project", devkey, username, password);

        YouTubeRequest youtubereq = new YouTubeRequest(youtubereqsetting);

        LiveBroadcastSnippet broadcastSnippet = new LiveBroadcastSnippet();

        broadcastSnippet.Title = "Test Live Stream";
        broadcastSnippet.ScheduledStartTime = new DateTime(2015, 3, 12, 19, 00, 00);
        broadcastSnippet.ScheduledEndTime = new DateTime(2015, 3, 12, 20, 00, 00);


        LiveBroadcastStatus status = new LiveBroadcastStatus();
        status.PrivacyStatus = "Private";

        LiveBroadcast broadcast = new LiveBroadcast();

        broadcast.Kind = "youtube#liveBroadcast";
        broadcast.Snippet = broadcastSnippet;
        broadcast.Status = status;

        Google.Apis.YouTube.v3.LiveBroadcastsResource.InsertRequest liveBroadcastInsert = new Google.Apis.YouTube.v3.LiveBroadcastsResource.InsertRequest(service, broadcast, "");            
        LiveBroadcast returnLiveBroadcast = liveBroadcastInsert.Execute();

私を助けてください!?!?!?

4

2 に答える 2

4

これが私がそれを機能させる方法です:

  1. アプリの作成 - Google デベロッパー コンソール
  2. アプリで API を有効にする - Youtube Data API v3
  3. OAuth クライアント ID の作成 - OAuth 資格情報の作成
  4. アプリケーションの種類は [その他] に設定する必要があります
  5. クライアント ID とクライアント シークレットを安全な場所にコピーします。
  6. 次の URL にアクセスします (ライブ ストリームをブロードキャストする Google アカウントでログインする必要があります)。

https://accounts.google.com/o/oauth2/auth?client_id= CLIENT_ID &scope= https://gdata.youtube.com&response_type=code&access_type=offline&redirect_uri=urn:ietf:wg:oauth:2.0:oob

ステップ 3で生成されたクライアント ID でCLIENT_IDを変更します。

  1. 生成されたトークンをページの入力テキスト ボックスからコピーします。
  2. ツール (cURL、wget、Google Chrome の Postman プラグインなど) を使用して、次の URL に POST 要求を行います。

    https://accounts.google.com/o/oauth2/token

    次のフィールドを使用して、この URL にx-www-form-urlencoded の HTTP POST を作成します(client_id、client_token、およびコードのみを変更し、最初の 2 つはそのままにしておきます)。

    {
        grant_type=authorization_code,
        redirect_uri=urn:ietf:wg:oauth2.0:oob,
        code=token_from_step_6_&_7
        client_id=your_client_id,
        client_secret=your_client_secret,
    }
    
  3. ここまで問題がなければ、次のような応答が返されます。

    {
    "access_token" : "次の数分間有効なトークン。これは必要ありません",
    "token_type" : "ベアラー",
    "expires_in" : 3600,
    "refresh_token" : "オフライン アプリで有効なトークン。これをコピーして保存してください"
    }
    
  4. これで、必要なすべての認証データ (client_id、client_secret、refresh_token) が揃ったので、API を試してみましょう。
        public String CreateLiveBroadcastEvent(String eventTitle, DateTime eventStartDate)
       {
            ClientSecrets シークレット = 新しい ClientSecrets()
            {
                ClientId = CLIENT_ID、
                ClientSecret = CLIENT_SECRET
            };
            var token = new TokenResponse { RefreshToken = REFRESH_TOKEN };
            var credentials = new UserCredential(new GoogleAuthorizationCodeFlow(
            新しい GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = シークレット }),
            "ユーザー"、トークン);
            var service = new YouTubeService(new BaseClientService.Initializer
            {
                HttpClientInitializer = 資格情報、
                ApplicationName = "あなたのアプリ名"
            });
            var ブロードキャスト = 新しい LiveBroadcast
            {
                Kind = "youtube#liveBroadcast",
                Snippet = 新しい LiveBroadcastSnippet
                {
                    タイトル = イベントタイトル、
                    ScheduledStartTime = eventStartDate
                }、
                ステータス = 新しい LiveBroadcastStatus { PrivacyStatus = "public" }
            };
            var request = service.LiveBroadcasts.Insert(broadcast, "id,snippet,status");
            var 応答 = request.Execute();
            response.Id を返します。
        }
    
于 2016-05-06T02:38:07.910 に答える