我正在尝试向Freshbooks的API发布帖子,但是,我还不能让它工作。在文档中,它们显示了如何使用Curl发出请求的示例。
请求api.freshbooks.com/auth/oauth/token:
curl -X POST -H "Api-Version: alpha" -H "Content-Type: application/json" -d '{
"grant_type": "authorization_code",
"client_secret": "<insert your secret>",
"code": "<insert your authorization code>",
"client_id": "<insert your client id>",
"redirect_uri": "https://localhost:3000/just_an_example"
}' "https://api.freshbooks.com/auth/oauth/token"
我正在使用ColdFusion,这是我的方法,但我总是得到500内部服务器错误。
function getAccessToken( String code ){
var httpService = new http();
var body = {};
httpService.setMethod("post");
httpService.setUrl( getApiUrl() );
httpService.addParam(type="header", name="Content-Type", value="application/json");
httpService.addParam(type="header",name="Api-Version",value="alpha");
body.grant_type = "authorization_code";
body.client_secret = getClientSecret();
body.code = arguments.code;
body.client_id = getClientID();
body.redirect_uri = "https://mywebsite.com";
serializedStr = serializeJSON( body );
var result = httpService.send().getPrefix();
return result;
}
我做错了什么?