1

1 According to this guide I created API Client;

2 I try to run this Apps Script to get access token and get error 502.

var url = "https://connect-api.cloud.huawei.com/api/oauth2/v1/token";

  var options =
  {
    "method" : "POST",
    "contentType" : "application/json",    
    "payload" : {
      "grant_type" : "client_credentials",
      "client_id" : "700000000000000000",
      "client_secret" : "4*********************A"
    }
  };

  var response = UrlFetchApp.fetch( url, options);
  Logger.log(response);

Is anybody can test this small code? Have you propositions?

Style-7
  • 985
  • 12
  • 27

2 Answers2

0

Is it possible to use Huawei developer API via Google Apps Script?

As far as I know, Huawei doesn't have any restrictions, but it's not clear if Google does.

I try to run this Apps Script to get access token and get error 502.

error 502 indicates that a network error between servers on the internet, meaning the problem wouldn't be with your computer or internet connection. Meanwhile you can try:

  • Refreshing/reloading the page
  • Closing all open tabs or windws and start a new session.
  • Clearing your Browser’s Cache and Cookies.
  • If none of above worked, try Another Browser or restart your PC.
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
0

Fixed!

var url = "https://connect-api.cloud.huawei.com/api/oauth2/v1/token";  
  var options =
    {
      method : "POST",
      contentType : "application/json",
      payload:JSON.stringify({
        "grant_type":"client_credentials",
        "client_id":"000000000000000000",            
        "client_secret":"LONG_STRING"
      })      
    };

  var response = UrlFetchApp.fetch( url, options);
  var access_token = JSON.parse(response.getContentText()).access_token;
Style-7
  • 985
  • 12
  • 27