工作Ebay Oauth Node Express JavaScript
三天来,我一直试图让E-bay的OAuth给我一个访问令牌,但这让我很沮丧,我终于找到了答案。由于这些文档很痛苦,而且网上几乎没有帮助,我决定在这里发布我的解决方案,希望它能帮助其他人。我不擅长stackoverflow,所以如果需要改进格式,请告诉我工作Ebay Oauth Node Express JavaScript,javascript,api,express,oauth,ebay-api,Javascript,Api,Express,Oauth,Ebay Api,三天来,我一直试图让E-bay的OAuth给我一个访问令牌,但这让我很沮丧,我终于找到了答案。由于这些文档很痛苦,而且网上几乎没有帮助,我决定在这里发布我的解决方案,希望它能帮助其他人。我不擅长stackoverflow,所以如果需要改进格式,请告诉我 app.get("/login/ebay", (req, res) => { res.redirect( `https://auth.sandbox.ebay.com/oauth2/authorize?cli
app.get("/login/ebay", (req, res) => {
res.redirect(
`https://auth.sandbox.ebay.com/oauth2/authorize?client_id=DeanSchm-TestApp-SBX-b843acc90-fd663cbb&redirect_uri=Dean_Schmid-DeanSchm-TestAp-kqmgc&response_type=code`
);
});
您需要做的第一件事是重定向到此url
格式是这样的
https://auth.sandbox.ebay.com/oauth2/authorize?client_id=<your_client_id>&redirect_uri=<your_redirect_uri>&response_type=code
一些让我抓狂的陷阱
- 确保在
标题authorization
是一个第三方库,它对您的公共和 秘密钥匙。有很多方法可以做到这一点。我就是这么做的 因为我偷了一堆代码bota
- 使用
时,请求主体称为数据,但使用fetch和other 方法它可以被称为body或axios
-axios方法位于get请求中,因为e-bay的重定向默认为http ge`tparam
- e-bay现在使用
https
- 确保您使用的是沙盒URL
app.get("/auth/ebay/callback", (req, res) => {
axios("https://api.sandbox.ebay.com/identity/v1/oauth2/token", {
method: "post",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization:
"Basic " +
btoa(
`client public key:client secret keys`
)
},
data: qs.stringify({
grant_type: "authorization_code",
// parsed from redirect URI after returning from eBay,
code: req.query.code,
// this is set in your dev account, also called RuName
redirect_uri: "Dean_Schmid-DeanSchm-TestAp-kqmgc"
})
})
.then(response => console.log(response))
.catch(err => console.log(err));
});