Google Community Connector oAuth2 проблема Gdrive

Я пытаюсь создать основной коннектор сообщества, используя эту ссылку.

Проблема возникает, когда я захожу на страницу источника данных и нажимаю кнопку " Авторизовать": она просто открывает пустое всплывающее окно. Пожалуйста, кто-нибудь может сообщить мне, в чем проблема с моим кодом.

code.js:

function getDriveService() {
// Create a new service with the given name. The name will be used when
// persisting the authorized token, so ensure it is unique within the
// scope of the property store.
return OAuth2.createService('drive')

  // Set the endpoint URLs, which are the same for all Google services.
  .setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
  .setTokenUrl('https://accounts.google.com/o/oauth2/token')

  // Set the client ID and secret, from the Google Developers Console.
  .setClientId('')
  .setClientSecret('')

  // Set the name of the callback function in the script referenced
  // above that should be invoked to complete the OAuth flow.
  .setCallbackFunction('authCallback')

  // Set the property store where authorized tokens should be persisted.
  .setPropertyStore(PropertiesService.getUserProperties())

  // Set the scopes to request (space-separated for Google services).
  .setScope('https://www.googleapis.com/auth/drive')

  // Below are Google-specific OAuth2 parameters.

  // Sets the login hint, which will prevent the account chooser screen
  // from being shown to users logged in with multiple accounts.
  .setParam('login_hint', Session.getActiveUser().getEmail())

  // Requests offline access.
  .setParam('access_type', 'offline')

  // Forces the approval prompt every time. This is useful for testing,
  // but not desirable in a production application.
  .setParam('approval_prompt', 'force');
}


function showSidebar() {
var driveService = getDriveService();
if (!driveService.hasAccess()) {
var authorizationUrl = driveService.getAuthorizationUrl();
var template = HtmlService.createTemplate(
    '<a href="<?= authorizationUrl ?>" target="_blank">Authorize</a>. ' +
    'Reopen the sidebar when the authorization is complete.');
template.authorizationUrl = authorizationUrl;
var page = template.evaluate();
DocumentApp.getUi().showSidebar(page);
} else {
// ...
}
}


function authCallback(request) {
var driveService = getDriveService();
var isAuthorized = driveService.handleCallback(request);
if (isAuthorized) {
return HtmlService.createHtmlOutput('Success! You can close this tab.');
} else {
return HtmlService.createHtmlOutput('Denied. You can close this tab');
}
}


function makeRequest() {
var driveService = getDriveService();
var response = UrlFetchApp.fetch('https://www.googleapis.com/drive/v2/files? 
maxResults=10', {
headers: {
  Authorization: 'Bearer ' + driveService.getAccessToken()
}
});
// ...
}

function logout() {
var service = getDriveService()
service.reset();
}

appsscript.json

{
"timeZone": "Asia/Karachi",
"dependencies": {
"libraries": [{
  "userSymbol": "OAuth2",
  "libraryId": "1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF",
  "version": "26"
}]
},
"dataStudio": {
"name": "Google Drive Metadata",
"logoUrl": 
"https://www.gstatic.com/images/branding/product/1x/google_fonts_48dp.png",
"company": "Webemblaze",
"addonUrl": "https://developers.google.com/datastudio/connector/getstarted",
"supportUrl": "https://developers.google.com/datastudio/connector/faq",
"description": "This connector uses the Google Fonts Developer API to retrieve metadata for all font families served by Google."
 },
 "exceptionLogging": "STACKDRIVER"

 }

1 ответ

Пожалуйста, обратитесь к документации по Аутентификации с OAuth 2.0, чтобы понять, как вы можете использовать OAuth2 с Community Connector. Вы также можете просмотреть пример кода для GitHub Connector, который использует OAuth2.

Другие вопросы по тегам