所以我有一個我正在使用的網站,其中包括使用Google的YouTube Data API v3搜索視頻(我正在使用JavaScript庫)。在將新代碼包含在同一頁面上導入Google +的代碼以使用其共享功能之前,一切正常。現在,無論何時加載網頁,YouTube視頻搜索和Google Plus共享似乎都無效。下面是YouTube的數據API客戶端負載和搜索代碼:我在Google Plus和Youtube Data API之間存在衝突問題?
function initializeGapi() {
gapi.client.setApiKey(API_KEY); // client API_KEY variable for client
gapi.client.load('youtube', 'v3',
function() {
console.log('Youtube API loaded.');
searchYoutube(''); // searches youtube
}
);
}
此HTML標記包含在頁面的標題:
<script src="https://apis.google.com/js/client.js?onload=OnLoadCallback"></script>
所以,一切運作良好。現在的問題是,當我下面介紹的代碼,谷歌加了它的分享按鈕功能:
<div id="googlepluscta"> // share button
<button
class="g-interactivepost"
data-contenturl="https://plus.google.com/pages/"
data-contentdeeplinkid="/pages"
data-clientid="142489821045.apps.googleusercontent.com"
data-cookiepolicy="single_host_origin"
data-prefilltext="Engage your users today, create a Google+ page for your business."
data-calltoactionlabel="CREATE"
data-calltoactionurl="http://plus.google.com/pages/create"
data-calltoactiondeeplinkid="/pages/create">
Tell your friends
</button>
</div>
另外,右邊的標籤,才能將加載谷歌Plus客戶端執行以下操作:
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
我已經包括屏幕截圖的聯繫,以及在情況下,他們可能會有所幫助:
非常感謝您的幫助!直到現在,我還沒有意識到你已經評論過:)刪除頁面頂部的額外腳本插件可以大大提高速度。我還添加了「initializeGapi」函數作爲上面在我留下的導入腳本中提到的URL回調。不過,我仍然遇到同樣的問題,YouTube上的網頁和視頻加載正常(當然使用YouTube數據API)。但是,只要我登錄Google Plus,然後嘗試使用YouTube Data API再次搜索,我仍然收到錯誤。我收到POST迴應403「權限不足」: – Hezell
啊!增加了更多信息。 – class
嘿,這解決了這個問題,現在它完美的工作!我完全忽略了數據範圍領域,甚至沒有注意到。非常感謝你的幫助類! – Hezell