2016-08-24 2 views
2

사이트에서 제공하는 zoom.us API를 사용하려고합니다. 위의 단지 자리는 'API_KEY'와 'api_secret'에 대한 변수 :cURL 명령을 아약스로 변환

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); 
     } 
    }); 

(주 그들은 나에게 새로운 사용자를 생성 할 수있는 curl 명령을 제공 예 :이 API 호출을 할 때 사용하는 고유 한 키와 비밀이 있습니다.

이 코드는 나를 위해 작동하지 않습니다. 다음 403 오류가 발생합니다.

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. 

내 질문은 무엇입니까? 내가 뭘 잘못하고있는 걸까요? 내가 잘못 번역 한 것이 있습니까? 또한, 이전에 유사한 질문을했습니다. (위의 번역 된 코드를 생각해 냈습니다.) 그러나 내 문제를 해결할 수 없었습니다.

유용한 정보를 보려면 다음과 같은 zoom.us 설명서가 필요합니다. https://support.zoom.us/hc/en-us/articles/201363033-REST-User-API

ETA는 :

$.ajax({ 
    url: 'https://api.zoom.us/v1/user/create', 
    cache: true, 
    async: false, 
    data: { 'api_key': 'key', 'api_secret': 'secret', 'email': e, 'first_name': 'john', 'last_name': 'smith' }, 
    success: function (res) { 
     console.log(res); 
    }, 
    error: function (err) { 
     console.error(err); 
    } 
}); 

새로운 405 오류가 발생합니다 : 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=Gon‌​zalez. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'website.com'; is therefore not allowed access. 
+2

POST 데이터 및 JSON 데이터는 같은 것이 아니다. 당신은 그것을 strigifying하지 않고 개체를 전달해야합니다. 또한 내용 유형을 변경하지 마십시오. – apokryfos

+3

일반적으로 CORS (교차 출처 자원 공유)라고합니다. 모든 클라이언트 컴퓨터에 API 키/비밀을 두는 것은 잘못된 일이라고 생각합니다. –

+0

감사합니다 @ 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'헤더가 요청 된 리소스에 없습니다. 따라서 'http://website.com'의 출처는 액세스 할 수 없습니다. 응답에는 HTTP 상태 코드 405가 있습니다. – Juan

답변

0

@apokryfos 덕분에 정답을 찾을 수있었습니다.

$.ajax({ 
    url: 'https://crossorigin.me/https://api.zoom.us/v1/user/create', 
    type: "POST", 
    cache: true, 
    async: false, 
    data: { 'api_key': 'key', 'api_secret': 'secret', 'email': e, 'first_name': f, 'last_name': l }, 
    success: function (res) { 
     console.log(res); 
    }, 
    error: function (err) { 
     console.error(err); 
    } 
}); 

}

+0

또한 API 공급자와 통신하여 브라우저가 해당 웹 서비스의 HTTP 오류를 CORS 위반으로 해석했음을 알리는 것이 좋습니다. CORS 위반이 없습니다. 원격 서버가 CORS 요청을 수락한다는 것을 나타내지 않으므로 브라우저가 그 오류를 가정합니다. – apokryfos

1

TR 한 번 데이터 유형을 추가하십시오. 'jsonp'는 벨로우즈와 같습니다.

$.ajax({ 
    url: 'https://api.zoom.us/v1/user/create', 
    cache: true, 
    dataType: 'jsonp' 
    async: false, 
    data: { 'api_key': 'key', 'api_secret': 'secret', 'email': e, 'first_name': 'john', 'last_name': 'smith' }, 
    success: function (res) { 
     console.log(res); 
    }, 
    error: function (err) { 
     console.error(err); 
    } 
});