2017-05-13 5 views
0

이것은 아마도 매우 간단한 문제 일 수 있습니다. 그러나 저는 curl을 처음 접했고 제대로 설명하지 못했습니다. curl을 통해 액세스 토큰을 가져와야하는 것은 이번이 처음이며 예제를 본 적이 없습니다. 내 Google 검색이 도움이되지 않았습니다.Google Apps 스크립트 및 말림

일단 액세스 토큰을 갖고 있지만 해당 단계로 이동 토큰을 가져올 수 없으면 트랜잭션 요청을하는 방법을 알고 있습니다. 다음은

는 토큰을 얻는 방법의 API 문서의 예입니다 : 내가 UrlFetchApp 이후 Google Apps Script에서이 호출이 URL을 필요로하게 생각하고 어떻게

curl -X POST -u <API USERNAME>:<API SECRET KEY> https://api.neverbounce.com/v3/access_token\ 
-d grant_type=client_credentials\ 
-d scope=basic+user 

을하지만,이 예제의 URL은의 일부입니다 의뢰?

function NBpost() { 
    var dataString = 'grant_type=client_credentials&scope=basic+user'; 
    var url = "https://api.neverbounce.com/v3/access_token"; 
    var options = 
    { 
     "method" : "post", 
     "auth": { 
     'user': <USERNAME>, 
     'pass': <SECRET KEY>, 
     }, 
     body : dataString, 
     "muteHttpExceptions" : true 
    }; 
    var response = JSON.parse(UrlFetchApp.fetch(url, options).getContentText()); 
} 
는 응답은 항상 동일

:

error:"invalid_request", 
error_description:"The grant type was not specified in the request" 

나는 또한 시도 :

var dataString = { 
    "grant_type": "client_credentials", 
    "scope" : "basic user" 
}; 
이 내 코드의 샘플입니다

UPDATE

그러나 응답은 변경되지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

이 나는 ​​다음과 같이 변경 만든 UPDATE :

error:"invalid_client" 
error_description:"Client credentials were not found in the headers or body" 

답변

2

어떻게 샘플 스크립트를 다음에 대해 :

function myFunction(){ 
    var url ='https://api.neverbounce.com/v3/access_token'; 
    var options = { 
     method: "post", 
     u: { 
     <USERNAME> : <SECRET KEY> 
     }, 
     payload: { 
     "grant_type": "client_credentials", 
     "scope": "basic user" 
     }, 
     muteHttpExceptions: true 
    }; 
    var response = JSON.parse(UrlFetchApp.fetch(url, options).getContentText()); 
} 

는 지금, 나는이 오류가? <API USERNAME><API SECRET KEY>이 없기 때문에 이것이 정상적으로 작동하는지 여부를 알 수 없습니다.

샘플 스크립트 :

var apiusername = <API USERNAME> 
var apisecretkey = <API SECRET KEY> 
var url ='https://api.neverbounce.com/v3/access_token'; 
var options = { 
    method: 'post', 
    headers : {"Authorization" : " Basic " + Utilities.base64Encode(apiusername + ":" + apisecretkey)}, 
    payload: { 
    "grant_type": "client_credentials", 
    "scope": "basic+user" 
    }, 
    muteHttpExceptions: true 
}; 
var response = JSON.parse(UrlFetchApp.fetch(url, options).getContentText()); 

이 작동하지 않거나 내가 질문을 오해하는 경우, 미안합니다.

+0

시도해 봤지만 감사합니다. 예외 : 로그인 정보가 허용되지 않습니다. – davids

+0

죄송합니다. 나는 지금 그것을 새롭게했다. 여기에는 헤더에 대한 기본 인증이 포함됩니다. 그것을 시도하십시오. – Tanaike