Итак, я пытаюсь создать прямой эфир с помощью этого API и, надеюсь, получить ключ потока и URL-адрес видео в ответ, но я получаю 500. oauth работает отлично, и да, я нажал кнопку после входа в систему (я исправлю код, чтобы проверить это позже):
Javascript:
<script>
var GoogleAuth;
var SCOPE = 'https://www.googleapis.com/auth/youtube.force-ssl';
function handleClientLoad() {
// Load the API's client and auth2 modules.
// Call the initClient function after the modules load.
gapi.load('client:auth2', initClient);
}
function initClient() {
// Retrieve the discovery document for version 3 of YouTube Data API.
// In practice, your app can retrieve one or more discovery documents.
var discoveryUrl = 'https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest';
// Initialize the gapi.client object, which app uses to make API requests.
// Get API key and client ID from API Console.
// 'scope' field specifies space-delimited list of access scopes.
gapi.client.init({
'apiKey': 'Sorry_had_to_delete_this_;)',
'discoveryDocs': [discoveryUrl],
'clientId': 'and_this_too_;)',
'scope': SCOPE
}).then(function () {
GoogleAuth = gapi.auth2.getAuthInstance();
// Listen for sign-in state changes.
GoogleAuth.isSignedIn.listen(updateSigninStatus);
// Handle initial sign-in state. (Determine if user is already signed in.)
var user = GoogleAuth.currentUser.get();
setSigninStatus();
// Call handleAuthClick function when user clicks on
// "Sign In" button.
$('#sign-in-or-out-button').click(function() {
handleAuthClick();
});
});
}
function handleAuthClick() {
if (GoogleAuth.isSignedIn.get()) {
// User is authorized and has clicked 'Sign out' button.
GoogleAuth.signOut();
} else {
// User is not signed in. Start Google auth flow.
GoogleAuth.signIn();
}
}
function setSigninStatus(isSignedIn) {
var user = GoogleAuth.currentUser.get();
var isAuthorized = user.hasGrantedScopes(SCOPE);
if (isAuthorized) {
$('#sign-in-or-out-button').html('Sign out');
} else {
$('#sign-in-or-out-button').html('Sign In');
}
}
function updateSigninStatus(isSignedIn) {
setSigninStatus();
}
function execute() {
return gapi.client.youtube.liveBroadcasts.insert({
"part": "snippet,status,contentDetails",
"resource": {
"status": {
"privacyStatus": "unlisted",
"madeForKids": false
},
"snippet": {
"language": 'en',
"scheduledStartTime": "2020-04-04T16:28:30.30Z",
"title": "TestingAPIStream",
"description": "Testing the javascript API using stream"
},
"contentDetails": {
"enableEmbed": true
}
}
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
</script>
HTML:
<button id="sign-in-or-out-button">Sign In</button>
<button id="create_live_stream" onclick="execute()">Create Stream</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
Ошибка:
ошибка:
код: 500
сообщение: ноль