Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token: < (line 268, file "Code") #51

Open
Jstorms1991 opened this issue Jul 16, 2019 · 1 comment
Open

SyntaxError: Unexpected token: < (line 268, file "Code") #51

Jstorms1991 opened this issue Jul 16, 2019 · 1 comment

Comments

@Jstorms1991
Copy link

Just went step by step with the guide. Couldn't find any solution for the the error listed. Took a screenshot as well just in case. Thanks in advance.

Line 268 is listed below.

var data = JSON.parse(json);

Screen Shot 2019-07-15 at 11 16 19 PM

@blackrandom
Copy link

blackrandom commented Jul 21, 2019

The API for coinmarketcap has changed, you need to make an account now and update the code to use the new format, instructions here [https://pro.coinmarketcap.com/migrate/]. Here's the changes I had to make to get this working:

Updated parsed data, starts at line 105 for me. The value 'price_btc' is not in the new API so it still shows as 'undefined' on the spreadsheet. Not sure if anyone can fix this, but I don't use it as much so I left it unchanged.

    ssRates.getRange('A'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['id']);
    ssRates.getRange('B'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['name']);
    ssRates.getRange('C'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['symbol']);
    ssRates.getRange('D'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['cmc_rank']);
    ssRates.getRange('E'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['quote']['USD']['price']);
    ssRates.getRange('F'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['price_btc']);
    ssRates.getRange('G'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['quote']['USD']['volume_24h']);
    ssRates.getRange('H'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['quote']['USD']['market_cap']);
    ssRates.getRange('I'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['circulating_supply']);
    ssRates.getRange('J'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['total_supply']);
    ssRates.getRange('K'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['max_supply']);
    ssRates.getRange('L'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['quote']['USD']['percent_change_1h']);
    ssRates.getRange('M'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['quote']['USD']['percent_change_24h']);
    ssRates.getRange('N'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['quote']['USD']['percent_change_7d']);
    ssRates.getRange('O'+(c).toString()).setValue(myCoinsObj[myCoins[i]]['last_updated']);

The updated getCoins() function, you can change the 'limit' value if you want to get all the coins, this uses up more credits with coinmarketcap. 100 works for me so that's what I left it as is.

function getCoins() {

  var url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest"
  
  requestOptions = {
    method: 'GET',
    muteHttpExceptions: true,
    qs: {
      'start': '1',
      'limit': '100',
      'convert': targetCurrency.toUpperCase()
    },
    headers: {
      'X-CMC_PRO_API_KEY': 'KEY'
    }
  }
  var response = UrlFetchApp.fetch(url, requestOptions);  
  var json = JSON.parse(response.getContentText());
  var data = json['data'];

  return data;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants