简体   繁体   中英

How to pull data from Patreon into Google Sheets

I'm trying to pipe data from a specific Patreon Creator Page into a Google Spreadsheet such as: Member first name, member last name, tier, etc. etc.

I've read the Patreon Developers Documentation here although I don't fully understand it. https://docs.patreon.com

I've used the examples here to write my Apps Script: https://github.com/gsuitedevs/apps-script-oauth2

I've successfully connected Patreon to my Webapp and have granted access but still no data.

var CLIENT_ID = 'REDACTED';
var CLIENT_SECRET = 'REDACTED';

/**
 * Authorizes and makes a request to the Dropbox API.
 */
function run() {
  var service = getService();
  if (service.hasAccess()) {
    var url = 'https://www.patreon.com/api/user/4817740';
    var response = UrlFetchApp.fetch(url, {
      headers: {
        Authorization: 'Bearer ' + service.getAccessToken()
      },
      method: 'post',
      // The Content-Type header must be set to an empty string when passing no
      // JSON payload.
      contentType: ''
    });
    var result = JSON.parse(response.getContentText());
    Logger.log(JSON.stringify(result, null, 2));
  } else {
    var authorizationUrl = service.getAuthorizationUrl();
    Logger.log('Open the following URL and re-run the script: %s',
        authorizationUrl);
  }
}

/**
 * Reset the authorization state, so that it can be re-tested.
 */
function reset() {
  getService().reset();
}

/**
 * Configures the service.
 */
function getService() {
  return OAuth2.createService('Patreon')
      // Set the endpoint URLs.
      .setAuthorizationBaseUrl('https://www.patreon.com/oauth2/authorize')
      .setTokenUrl('https://www.patreon.com/api/oauth2/token')

      // Set the client ID and secret.
      .setClientId(CLIENT_ID)
      .setClientSecret(CLIENT_SECRET)

      // Set the name of the callback function 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 response type to code (required).
      .setParam();
}

/**
 * Handles the OAuth callback.
 */
function authCallback(request) {
  var service = getService();
  var authorized = service.handleCallback(request);
  if (authorized) {
    return HtmlService.createHtmlOutput('Success!');
  } else {
    return HtmlService.createHtmlOutput('Denied.');
  }
}

/**
 * Logs the redict URI to register in the Dropbox application settings.
 */
function logRedirectUri() {
  Logger.log(OAuth2.getRedirectUri());
}

I expect to see a list of data but instead I just keep getting this error and the log says "No logs found. Use Logger API to add logs to your project."

TypeError: Cannot read property "parameter" from undefined. (line 378, file "Service", project "OAuth2")

The error comes because the Oauth flow is not being completely executed (It may be that it's not presenting the consent screen, you're not logging in with your account, etc).

As stated in the Oauth2 library documentation for Apps Script that you're using [1] in the "Connecting to a Google API" part, a more simple way to obtain the access token is using ScriptApp.getOAuthToken() function [2] instead of service.getAccessToken() , and set the needed scopes in the manifest file [3].

In any case, I hardly believe that could give you access to the Patreon API [4]. Also, I don't see the url you're using in the Patreon API documentation [5].

[1] https://github.com/gsuitedevs/apps-script-oauth2

[2] https://developers.google.com/apps-script/reference/script/script-app#getoauthtoken

[3] https://developers.google.com/apps-script/concepts/manifests#editing_a_manifest

[4] https://docs.patreon.com/#oauth

[5] https://docs.patreon.com/?javascript#api-endpoints

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM