Hello !

J'en appelle à votre aide ! Je suis un peu perdu avec cet API Youtube v3, je vous explique mon problème. Je suis sur la création d'un thème Wordpress et je voudrais listé les vidéos d'une chaîne, donc j'ai installé le dossier "Google" dans mon thème depuis ce repo : https://github.com/google/google-api-php-client

Je l'appelle depuis un fichier config.php ou je renseigne mes clés que j'ai créer à partir de l'application que j'ai créer depuis console.developers.google.com et ça m'affiche ça sur ma page :

"Authorization Required
You need to authorize access before proceeding."

Quand je clique sur "authorize access" ça me renvoi sur une erreur 400:

  1. That’s an error.

Error: redirect_uri_mismatch

Application: Project Default Service Account

You can email the developer of this application at: xxxxxxxxxxxxxx@gmail.com

The redirect URI in the request: http://mldeg.dev.com/index.php did not match a registered redirect URI

A mon avis ça vient par rapport à ce que j'ai remplit dans "Redirect URI" à savoir : https://mldeg.dev.com/oauth2callback/

6 réponses


Lunadoz
Réponse acceptée

C'est peut être un peu tard, tu a dans https://console.developers.google.com/ la gestion des clé API, mais surtout tu doit autorisé YoutubeData pour cela :
Api et authentification => Api => Recherche le module YoutubeData => Activé avec le switch en haut de la page

ta créer ton application dans Google developer ?
Tu lui à renseigner ta API_KEY ?
C'est quoi ton code php en rapport à google API ?

Shadows
Auteur

Concidérez que ma Secret key a été renseigné.

<?php
/**
 * This sample creates a channel section by :
 *
 * 1. Getting the active user's channel branding settings via "channels.list" method.
 * 2. Updating the active user's channel to show "browse view" via "channel.update" method.
 * 3. Creating a channel section in the active user's channel via "channelSections->insert" method.
 *
 * @author Ibrahim Ulukaya
*/

// Call set_include_path() as needed to point to your client library.
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
session_start();
// Valid section types.
$SECTION_TYPES = array("allPlaylists", "completedEvents", "likedPlaylists",
  "likes", "liveEvents", "multipleChannels", "multiplePlaylists",
  "popularUploads", "recentActivity", "recentPosts", "recentUploads",
  "singlePlaylist", "upcomingEvents");
// Valid section styles.
$SECTION_STYLES = array("horizontalRow", "verticalList");
// Replace with section title of your choice.
$SECTION_TITLE = 'YOUR_SECTION_TITLE';
// The section's position on the channel page. This property uses a 0-based index.
// If you do not specify a value for this property when inserting a channel section,
// the default behavior is to display the new section last.
$SECTION_POSITION = 0;
// A list of playlist IDs that will be featured in a channel section.
$PLAYLISTS = '';
// A list of channel IDs that will be featured in a channel section.
$CHANNELS = 'TheMLDEG';
/*
 * You can acquire an OAuth 2.0 client ID and client secret from the
 * Google Developers Console <https://console.developers.google.com/>
 * For more information about using OAuth 2.0 to access Google APIs, please see:
 * <https://developers.google.com/youtube/v3/guides/authentication>
 * Please ensure that you have enabled the YouTube Data API for your project.
 */
$OAUTH2_CLIENT_ID = '143418702769-u1r0gb3d9nr7hfvh9tt9nnpfigldr127.apps.googleusercontent.com';
$OAUTH2_CLIENT_SECRET = 'J'AI MIS MA SECRET KEY ICI';
$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes('https://www.googleapis.com/auth/youtube');
$redirect = filter_var('http://' . $_SERVER'HTTP_HOST'] . $_SERVER'PHP_SELF'],
    FILTER_SANITIZE_URL);
$client->setRedirectUri($redirect);
// Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
if (isset($_GET'code'])) {
  if (strval($_SESSION'state']) !== strval($_GET'state'])) {
    die('The session state did not match.');
  }
  $client->authenticate($_GET'code']);
  $_SESSION'token'] = $client->getAccessToken();
  header('Location: ' . $redirect);
}
if (isset($_SESSION'token'])) {
  $client->setAccessToken($_SESSION'token']);
}
// Check to ensure that the access token was successfully acquired.
if ($client->getAccessToken()) {
  try {
    /*
     * Before channel shelves will appear on your channel's web page, browse
     * view needs to be enabled. If you know that your channel already has
     * it enabled, or if you want to add a number of sections before enabling it,
     * you can skip the call to enable_browse_view().
     */
    // Call the YouTube Data API's channels.list method to retrieve your channel.
    $listResponse = $youtube->channels->listChannels('brandingSettings', array('mine' => true));
    $channel = $listResponse'items'][0];
    $channel'brandingSettings']'channel']'showBrowseView'] = true;
    // Call the YouTube Data API's channels.update method to update your channel.
    $updateResponse = $youtube->channels->update('brandingSettings', $channel);
    // Create a channel section snippet object with type, style, title and position.
    $channelSectionSnippet = new Google_Service_YouTube_ChannelSectionSnippet();
    $channelSectionSnippet->setType($SECTION_TYPES[0]);
    $channelSectionSnippet->setStyle($SECTION_STYLES[0]);
    $channelSectionSnippet->setTitle($SECTION_TITLE);
    $channelSectionSnippet->setPosition($SECTION_POSITION);
    // Create a channel section contentDetails object with channels and playlists.
    $channelSectionContentDetails = new Google_Service_YouTube_ChannelSectionContentDetails();
    $channelSectionContentDetails->setChannels($CHANNELS);
    $channelSectionContentDetails->setPlaylists($PLAYLISTS);
    // Create a channel section with snippet and contentDetails.
    $channelSection = new Google_Service_YouTube_ChannelSection();
    $channelSection->setSnippet($channelSectionSnippet);
    $channelSection->setContentDetails($channelSectionContentDetails);
    // Call the YouTube Data API's channelSections.insert method to create a channel section.
    $insertResponse = $youtube->channelSections->insert('snippet,contentDetails', $channelSection);
    $htmlBody .= "<h2>Section Created</h2><ul>";
    $htmlBody .= sprintf('<li>%s "%s"</li>',
        $insertResponse'id'], $insertResponse'snippet']'title']);
    $htmlBody .= '</ul>';
    $htmlBody .= "<h3>with channels</h3><ul>";
    foreach ($insertResponse'contentDetails']'channels'] as $channel) {
      $channels .= sprintf('<li>%s</li>', $channel);
    }
    $htmlBody .= '</ul>';
    $htmlBody .= "<h3>with playlists</h3><ul>";
    foreach ($insertResponse'contentDetails']'playlists'] as $playlist) {
      $channels .= sprintf('<li>%s</li>', $playlist);
    }
    $htmlBody .= '</ul>';
  } catch (Google_ServiceException $e) {
    $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
        htmlspecialchars($e->getMessage()));
  } catch (Google_Exception $e) {
    $htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
        htmlspecialchars($e->getMessage()));
  }
  $_SESSION'token'] = $client->getAccessToken();
} else {
  // If the user hasn't authorized the app, initiate the OAuth flow
  $state = mt_rand();
  $client->setState($state);
  $_SESSION'state'] = $state;
  $authUrl = $client->createAuthUrl();
  $htmlBody = <<<END
  <h3>Authorization Required</h3>
  <p>You need to <a href="$authUrl">authorize access</a> before proceeding.<p>
END;
 }
    ?><?=$htmlBody?>
Shadows
Auteur

Up

Pour plus détails je travaille en local avec un virtual host qui est http://mldeg.dev.com et dans Redirect URI j'ai mis ça : http://mldeg.dev.com/oauth2callback

et l'erreur ça me sort :

scope=https://www.googleapis.com/auth/youtube
response_type=code
access_type=online
redirect_uri=http://mldeg.dev.com/index.php
pageId=none
approval_prompt=auto
state=1733102730
client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent

Shadows
Auteur

UP

Shadows
Auteur

UP