Ich baue derzeit eine ASP.NET-Webanwendung zur Vereinfachung der Bereitstellung von Google Sites, Seiten, Gadgets auf Google Sites und ACLs für Google Sites.CORS authentifizierte Anfragen an Google Sites-Feed/API blockiert
Ich bin auf das Problem gestoßen, auf das viele Entwickler bereits gestoßen sind: ursprungsübergreifende Ressourcen. Laut der Google-Dokumentation zu CORS-Anfragen an Google-APIs verwenden Sie einfach eine XMLHttpRequest (oder AJAX) -Anforderung, die Ihr Zugriffstoken in der Kopfzeile bereitstellt. Weitere Informationen finden Sie hier:
https://developers.google.com/api-client-library/javascript/features/cors
Ich habe durchaus in der Lage gewesen, dies zu tun, wenn ich den Google Sites-API von innerhalb meiner Domain auf Google Site zugreifen, die Injektion von AJAX Anfragen während meines Browserfensters Standorts ist innerhalb der Domäne. Ein Beispiel für einen gelungenen Anfrag eine neue Seite zu machen aus meiner Domain:
$.ajax(
{
////// REQUEST \\\\\\
type: "POST",
url: "https://sites.google.com/feeds/site/[domainName]",
contentType: "application/atom+xml",
headers: {
"Authorization": "Bearer " + [accessToken],
"GData-Version": "1.4"
},
data: ["<entry xmlns='http://www.w3.org/2005/Atom' xmlns:sites='http://schemas.google.com/sites/2008'>",
"<title>What a site</title>",
"<summary>Best description ever.</summary>",
"<sites:theme>ski</sites:theme>",
"</entry>"].join(""),
////// LOGGING \\\\\\
beforeSend: function() {
console.log('-------Making-the-request-------');
},
success: function (result) {
console.log(result);
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(thrownError);
console.log(xhr.status);
}
});
(In mehreren Fällen unten, ich bin https schreiben: // als [https] wegen meines Konto noch auf 2 beschränkt zu sein Links in einem Post).
An diesem Punkt lief alles gut, ich dachte, ich hätte alles, um den Code in meine ASP.NET-Site zu verwenden. Leider laufen die Dinge nicht immer nach Plan. Wenn ich den exakt gleichen AJAX-Aufruf von innerhalb meiner Anwendung (jetzt noch gehostet [https] localhost: 44301) ausgeführt, erhalte ich folgende Fehlermeldung:
XMLHttpRequest cannot load [https]sites.google.com/feeds/site/[censored] Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '[https]localhost:44301' is therefore not allowed access. The response had HTTP status code 405.
Die üblichen CORS Fehler. Ich war jedoch überrascht, da die empfohlene Art, Anfragen an Google APIs zu stellen, genau das ist. Ich habe auch festgestellt, einen Artikel über CORS mit dem Google Cloud-API:
https://cloud.google.com/storage/docs/cross-origin
In dem Artikel heißt es:
Most clients (such as browsers) use the XMLHttpRequest object to make a cross-domain request. XMLHttpRequest takes care of all the work of inserting the right headers and handling the CORS interaction with the server. This means you don't add any new code to take advantage of CORS support, it will simply work as expected for Google Cloud Storage buckets configured for CORS.
Natürlich ist dies nicht der Google Sites-API, Es fällt mir jedoch schwer zu glauben, dass Google nicht in allen seinen APIs dieselbe Funktionalität implementiert hat.
Weiß jemand, ob es möglich ist, erfolgreiche Anfragen wie diese aus einer eigenständigen ASP.NET-Anwendung heraus zu erreichen? Und wenn ja, wie?
Vielen Dank für die Zeit zu lesen, über meine Nöte.
UPDATE:
ich Google Apps-Support in Bezug auf meine Frage in Kontakt gebracht haben, und haben die folgende Antwort bekommen:
In addition to the information you provided, I also reviewed your post at CORS authenticated requests to Google Sites feed/API blocked . The note at https://developers.google.com/google-apps/sites/docs/1.0/developers_guide_java#SiteFeedPOST only reinforces the statement under 'Can I create a new Google Site?' and 'How do I copy a site?' at https://developers.google.com/google-apps/sites/faq#Getting__Started , which states 'Google Apps users can use the site feed to ...' However, I don't see why this is relevant to your issue, if you've authorised against your domain administrator account, as the note is only indicating that gmail.com users won't be able to use the listed methods to create, or copy a site.
I haven't used CORS, so can't comment on it's operation, but have been able to successfully list, and create sites using HTTP GET and POST requests via a raw HTTP client, so the API is operating as it should with regard to cross domain requests. I used the sample XML document at https://developers.google.com/google-apps/sites/docs/1.0/developers_guide_protocol#SitesFeedPOST to create my site, configuring the client with credentials for my Developer console project. The fact that the request only fails in your ASP.NET site implies that there is something in that environment which isn't configured correctly. Unfortunately that's outside my scope of support, so I'm unable to provide any specific advice, other than to check the relevant documentation, or post a request in the ASP.NET section of Stack Overflow at https://stackoverflow.com/questions/tagged/asp.net .
Sie können dies mit JSONP –