5

मैं क्रोम एक्सटेंशन में चैनल एपीआई का उपयोग कर रहा हूं।Google ऐप इंजन चैनल API (jsapi) क्रोम एक्सटेंशन में लोड करने में विफल क्यों होता है?

Google App Engine Channel API Javascript Reference (Python) पेज में यह कहा गया है कि

Include the following in your html page before any JavaScript code that refers to it:

<script type="text/javascript" src="/_ah/channel/jsapi"></script> 

तो, मैं डाल दिया है कि मेरे options.html फ़ाइल के शीर्षक में:

<html> 
<head> 
    <title>Extension Options</title> 
    <script type="text/javascript" src="/_ah/channel/jsapi"></script> 
</head> 

लेकिन क्रोम jsapiFailed to load resource त्रुटि फेंकता है। मैं क्या गलत कर रहा हूं?

अद्यतन

Moishe के जवाब के अनुसार, मैं इस तरह JSAPI करने के लिए कॉल अद्यतन:

<head> 
    <title>Extension Options</title> 
    <!-- this does not work because it is local 
    <script type="text/javascript" src="/_ah/channel/jsapi"></script> 
    --> 
    <script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script> 
</head> 

अद्यतन

मैं onopen और अन्य गुण गयी। अब मुझे onopen अलर्ट मिल गया है लेकिन मुझे evt.data अलर्ट नहीं मिल रहा है। मैं क्या गलत कर रहा हूं?

<html> 
<head> 
    <title>Extension Options</title> 
    <!-- this does not work because it is local url 
    <script type="text/javascript" src="/_ah/channel/jsapi"></script> 
    --> 
    <script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script> 
</head> 

<body> 
<p>Enter your gmail address:</p> 

<textarea id="getEmail" style="margin-bottom: 4px; width: 250px; height: 20px"> 
</textarea><br /> 

<button id="save">Save</button> 
<!--<button id="save">Clear</button>--> 

<script> 
document.getElementById("getEmail").placeholder = "your gmail address" ; 

//save entered gmail address 
document.getElementById("save").addEventListener 
(
    "click", 
    function() 
    { 
     var userEmail = document.getElementById("getEmail").value; 
     var formData = new FormData(); 
     formData.append("extension_user", userEmail); 
     alert("after formData.append") 

     var channel; 
     var socket; 
     var handler = 
     { 
      onopen: function() { alert("onopen") }, 
      onerror: function() { alert("onerror") }, 
      onclose: function() { alert("onclose") }, 
      onmessage: 
      function (evt) 
      { 
       //evt.data will be what the server sends in channel.send_message 
       console.log("evt.data received from authhandler: " + evt.data); 
       alert("evt.data is: " + evt.data) 
      } 
     };  

     var xhr = new XMLHttpRequest(); 
     //changed to lowercase 
     xhr.onreadystatechange = function() 
     { 
      //alert("xhr.onReadyStateChange") 
      //error handling etc not included 
      if (xhr.readyState == 4 && xhr.status == 200) 
      { 
       token = xhr.responseText; 
       alert("token: " + token) 
       channel = new goog.appengine.Channel(token); 
       socket = channel.open(handler); 
      } 
     }; 
     xhr.open("POST", "http://ting-1.appspot.com/authsender", true); 
     xhr.send(formData); 
     console.log("formData sent to authsender: " + formData); 
    }, false 
) 



</script> 
</body> 
</html> 
+0

क्या यह dev_appserver या उत्पादन में उपयोग कर रहा है? क्या आप क्रोम देव उपकरण में "नेटवर्क" टैब के लिए कोई विवरण प्रदान कर सकते हैं? –

+0

यह उत्पादन में है। सबसे पहले "नेटवर्क" टैब में कुछ भी नहीं था; तो मैंने निर्देश के अनुसार पेज को पुनः लोड किया और मुझे 2 आइटम दिखाई दिए: options.html और jsapi: name: options.html; विधि: प्राप्त करें; स्थिति: (कैश से); प्रकार: text/html; आकार: (कैश से); समय: 3 एमएमएस और 'जेएसपीआई/_ए/चैनल; प्राप्त करें, (असफल); अपरिभाषित; 30B; 5 एमएमएस धन्यवाद! – Zeynel

+0

क्या आप मुझे अपना एपिड बताते हैं? यदि आप सीधे "http://your-app-id.appspot.com/_ah/channel/jsapi" पर नेविगेट करने का प्रयास करते हैं तो क्या होता है? –

उत्तर

3

एक क्रोम विस्तार में, आप सीधे चैनल जावास्क्रिप्ट (https://talkgadget.google.com/talkgadget/channel.js) के लिए पथ निर्दिष्ट करने की आवश्यकता होगी।/_ah/channel/jsapi के लिए अनुरोध किसी भी चीज़ द्वारा पुनर्निर्देशित नहीं किया जा सकता है क्योंकि फ़ाइल लोड करने का प्रयास करने वाली फ़ाइल स्थानीय है।

+0

क्षमा करें, शीर्षक के बारे में मुझे "क्रोम एक्सटेंशन" का उल्लेख करना चाहिए था। अब मुझे मूल त्रुटि नहीं मिल रही है, लेकिन मुझे यकीन नहीं है कि यह मेरे कोड से संबंधित है: 'अनकॉट टाइप एरर: ऑब्जेक्ट की संपत्ति' ओपन 'ऑब्जेक्ट [ऑब्जेक्ट ऑब्जेक्ट] एक फ़ंक्शन नहीं है channel.js की लाइन 77। क्या यह मेरे 'फ़ंक्शन (evt)' के साथ किसी समस्या से संबंधित है? एक बार फिर धन्यवाद। – Zeynel

+0

मुझे नहीं पता कि यह प्रासंगिक है या नहीं, लेकिन नेटवर्क टैब दिखाता है कि 'बाइंड 235.talkgadget.google.com/talkgadget/dch' – Zeynel

+1

के लिए 200-ओके प्राप्त करें आपको अपने हैंडलर में एक ऑनपेन कॉलबैक निर्दिष्ट करने की आवश्यकता है। –

संबंधित मुद्दे