2017-01-22 41 views
0

我正嘗試使用Google融合表REST API https://developers.google.com/fusiontables/docs/v2/using提供的文檔創建融合表。 我在下面的格式如何正確發送使用Google OAuth2創建融合表的Ajax Post請求?

$.ajax({ type: "POST", crossDomain: true, contentType: "application/json", url: "https://www.googleapis.com/fusiontables/v2/tables", beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", token); }, data: { access_token: token, "name": "Insects", "columns": [ { "name": "Species", "type": "STRING" }, { "name": "Elevation", "type": "NUMBER" }, { "name": "Year", "type": "DATETIME" } ], "description": "Insect Tracking Information.", "isExportable": true }, async: false, success: function(result){ alert(result); }, error: function(result) { alert('error'); } });

Ajax請求,但我得到一個401錯誤。我嘗試設置承載,令牌授權頭,但仍然沒有success.Any指針將大大appreciated.Thank你

回答

0

我解決我的問題有:

xhr.setRequestHeader("Authorization", "Bearer "+ token);