Amazon paapi を golang で直接呼び出す時の signature 生成方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reqJson に json.Marshal したものが入っているとする | |
// APIHost = "webservices.amazon.co.jp" | |
// APIRegion = "us-west-2" | |
// APITarget = "com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems" | |
// APIService = "ProductAdvertisingAPI" | |
bodyReader := bytes.NewReader(reqJson) | |
req, err := http.NewRequest("POST", "https://" + APIHost + "/paapi5/searchitems", bodyReader) | |
log.Println("request:", req) | |
req.Header.Add("content-type", "application/json; charset=utf-8") | |
req.Header.Add("content-encoding", "amz-1.0") | |
req.Header.Add("x-amz-target", APITarget) | |
cred := credentials.NewStaticCredentials("自分のID", "キー", "") | |
signer := signer.NewSigner(cred) | |
body, err := ioutil.ReadAll(req.Body) | |
if err != nil { | |
// エラー処理 | |
} | |
_, err = signer.Sign(req, bytes.NewReader(body), APIService, APIRegion, time.Now()) | |
if err != nil { | |
// エラー処理 | |
} | |
// http.Client で req を送信 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
9 行目はドキュメントで探せなかったので、curl の出力を参考にした。