サイトで提供されているzoom.us APIを使用しようとしています。彼らは私に新しいユーザーを作成するためにcurlコマンド与える:cURLコマンドをajaxに変換する
curl --data 'api_key=your_api_key&api_secret=your_api_secret&[email protected]&type=1&first_name=John&last_name=Smith' https://api.zoom.us/v1/user/create
を私はAJAXに翻訳:
$.ajax({
url: 'https://api.zoom.us/v1/user/create',
type: "POST",
cache: true,
async: false,
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({ 'api_key': 'key', 'api_secret': 'secret', 'email': '[email protected]', 'first_name': 'John', 'last_name': 'Smith' }),
success: function (res) {
console.log(res);
},
error: function (err) {
console.error(err);
}
});
(注:「API_KEY」と「api_secret」の変数は、上記でちょうどプレースホルダですこのAPIコールを作成しようとするときに使用する独自のキーと秘密があります)
このコードは私にとっては機能しません。
XMLHttpRequest cannot load https://api.zoom.us/v1/user/create.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://mywebsite.com' is therefore not allowed access. The response had HTTP status code 403.
私の質問はこれです:私は、次の403エラーを取得する私が間違っているのでしょうか?私が誤って翻訳したものはありますか?また、私は前に同様の質問があったことを知っています(上の翻訳コードを思いついたのですが)。私は問題を解決できませんでした。
参考になる場合は、 https://support.zoom.us/hc/en-us/articles/201363033-REST-User-API
ETA:apokryfosさんのコメントの後に、ここに私の更新されたコードがあります:
XMLHttpRequest cannot load api.zoom.us/v1/user/create?api_key=key&api_secret =secret&email=test%40email.com&first_name=Juan&last_name=Gonzalez.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'website.com'; is therefore not allowed access.
POSTデータとJSONデータは同じものではありません。あなたはそれを密接させることなくオブジェクトを渡すべきです。また、コンテンツタイプを変更しないでください。 – apokryfos
一般的にCORS(クロスオリジンリソース共有)として知られています。私はすべてのクライアントマシンにapiの鍵/秘密を入れていると間違ったことをしていると思います。 –
ありがとう@apokryfos、私の403エラーを解決しましたが、今は新しい405エラーが発生しました:XMLHttpRequestはhttps://api.zoom.us/v1/user/create?api_key=key&api_secret = secret&email = test%40email.com&first_name = Juan&last_name =ゴンザレス。要求されたリソースに「Access-Control-Allow-Origin」ヘッダーが存在しません。したがって、Origin 'http://website.com'はアクセスできません。応答にHTTPステータスコード405が付きました。 – Juan