0
我正在嘗試對Shopify進行API OAUTH2調用進行身份驗證。當我去我的應用程序,第一個屏幕出現。我按下安裝,然後將我重定向到我開始的位置。問題是,當我重定向時,我似乎無法在我的jQuery ajax函數中捕獲它,因此我無法獲得我需要從OAUTH創建永久令牌的臨時令牌。第二張圖片顯示了我按下安裝後發生的情況。我的代碼到目前爲止在下面。在運行ajax調用之後,沒有任何console.log()函數被調用。使用jQuery OAUTH獲取臨時訪問令牌
爲我的應用我的應用程序URL設置爲
http://localhost
和我的應用程序從
http://localhost/shippingcalculator.
運行我測試了外部REST客戶端程序的調用,我設法順利拿到我的訪問令牌,所以它不是我的憑據問題。
<!DOCTYPE html>
<script type="text/javascript">
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
console.log(window.location.search);
var results = regex.exec(window.location.search);
if (results == null) return "";
else return decodeURIComponent(results[1].replace(/\+/g, " "));
}
function getTemporaryToken(token) {
jso_configure({
"shopify": {
client_id: "67d7af798dd0a42e731af51ffa", //This is your API Key for your App
//redirect_uri: "", OPTIONAL - The URL that the merchant will be sent to once authentication is complete. Must be the same host as the Return URL specified in the application settings
authorization: "https://emard-ratke3131.myshopify.com/admin/oauth/authorize",
//In your case the authorization would be https://SHOP_NAME.myshopify.com/admin/oauth/authorize
scope: ["read_products"], //Set the scope to whatever you want to access from the API. Full list here: http://api.shopify.com/authentication.html
}
});
$.oajax({
url: "https://emard-ratke3131.myshopify.com/admin/oauth/authorize",
jso_provider: "shopify",
jso_scopes: ["read_products"],
jso_allowia: true,
success: function(data) {
//Use data and exchange temporary token for permanent one
if (jqXHR.status === 200) {
console.log("200");
}
if (jqXHR.status === 302) {
console.log("300");
}
console.log("Response (shopify):");
console.log(data);
},
error: function(e) {
console.log("Fail GET Request");
console.log(e);
},
complete: function(xmlHttp) {
// xmlHttp is a XMLHttpRquest object
console.log(xmlHttp.status);
}
});
console.log("Code: " + getParameterByName("code"));
}
}
$(document).ready(function() {
getTemporaryToken();
});
</script>
</head>
<body>
Hello World!
</body>
</html>
好吧,我已經寫了一個node.js服務器來協助我的OAuth調用 – Marc 2012-07-11 22:46:38
在cookie或html5本地存儲器中存儲令牌不是壞主意 – sepehr 2016-10-26 07:18:49