2011-12-21 24 views
0

我正試圖遵循谷歌網絡商店API文檔中給出的這個簡單的例子。 不幸的是,他們最小的PHP示例包含了很多我不需要的東西(並且沒有安裝)。如何在使用Google網上應用店API時避免發生跨網站錯誤?

所以我期待在硬編碼的基本的東西到HTML文件中,只是爲了獲得與谷歌服務器的工作溝通:

我的代碼如下所示:

<html> 
    <head> 
    </head> 
    <body> 
    <script type="text/javascript" src="https://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 
     purchase = function() { console.log("Old purchase function"); } 
     generatedJwt = "..."; // I use a real JWT here.... 
     google.load('payments', '1.0', { 
      'packages': ['sandbox_config'], 
      callback: function() 
      { 
      //Success handler 
      var successHandler = function(purchaseAction){ 
       if (window.console != undefined) { 
       console.log("Purchase completed successfully.",purchaseAction); 
      } 
      } 

      //Failure handler 
      var failureHandler = function(purchaseActionError) 
      { 
      if (window.console != undefined) 
      { 
      console.log("Purchase did not complete.", purchaseActionError); 
     } 
      } 

      var purchase = function() 
      { 
      goog.payments.inapp.buy({ 
       'jwt'  : generatedJwt, 
       'success' : successHandler, 
       'failure' : failureHandler 
       }); 
      } 
     } 
     }); 
    </script> 
    <button class="buy-button" id="buybutton1" name="buy" type="button" onClick="purchase()"> 
     Buy 
    </button> 
</body> 

當我點擊購買按鈕時,我收到一條從google彈出的錯誤消息,並在控制檯中顯示以下錯誤:

Unsafe JavaScript attempt to access frame with URL 
http://localhost/google_iap/buy_page.html 
from frame with URL 
https://sandbox.google.com/checkout/inapp/static/gwt/payments.html?viewportScreenCenterX=-857.5&viewportScreenCenterY=611#id=I1_1324454042050&parent=http%3A%2F%2Flocalhost&rpctoken=166967692&_methods=onPurchaseActionStatus%2CgetJwt%2C_ready%2C_close%2C_open%2C_resizeMe. 
Domains, protocols and ports must match. 

爲了使這個簡單的例子工作,我需要做些什麼?

附錄:

我發現從谷歌一個更好的例子:

https://sandbox.google.com/checkout/customer/gadget/inapp/demo.html

然而保存源到我的機器和本地訪問它(如http://localhost/google_iap/google_demo.html)給出相同的跨域錯誤。

回答

0

看起來是google sandbox was broken。這是現在再次工作,所以這個例子似乎正常工作。不過,有關跨站點訪問的警告仍然存在。

相關問題