1

Facebookフィードを表示するGoogle Appsスクリプトを作成してGoogleサイトに埋め込むことができますが、それを行う方法についてはこれ以上の情報は見つかりません私自身。これはにFacebook開発から「FacebookのJavascriptのSDK」と「ページ送り」をコピーするからである新しいGoogleサイトにFacebookフィードを埋め込むには(Apps Scriptを使用します)?

Uncaught DOMException: Failed to set the 'domain' property on 'Document': Assignment is forbidden for sandboxed iframes. 

:私はFacebookのフィードをAppsスクリプトのWebアプリを作るしようとすると

は、私のようなエラーが発生しますHTMLファイルを作成し、Webアプリケーションとしてデプロイします。私はそれがAppsスクリプトがあなたのコードをどのようにサンドボックスしているかと関係があるが、ここで何をしなければならないか分からない。

静的なHTMLを使って簡単なAppsスクリプトを作成しようとしても、ドライブからサイトに埋め込みしようとすると「選択したアイテムの一部を埋め込むことができませんでした」というエラーが表示されます。

答えて

2

新しいGoogleサイトは、Google Apps Scriptをサポートしていません。

関連質問:Google App Scripts For New Google Sites Release

+0

(私は実際に戻ってフィードと協力するので、返されたデータ構造をチェックし、それに応じて調整していません)。はい。まあ、それは私のためにそれを使用してルールを推測する:/ – Zuko

0

新しいGoogleサイトは今(/あなた、ウェブアプリとしてアプリのスクリプトを展開することを確認し、右権限を設定、および/ execのURLを使用していない埋め込むアプリのスクリプトをサポートしています開発者は埋め込みます)。

私は、サンドボックス化のためにFacebookのSDKをビデオに使用できないことがわかりました。私は動画の代わりにiframeソリューションを使用しましたが、フィードのためにこのようなものを試してみることもできます(私はあなたが生成トークンを得るためにあなたのアプリをfbに登録したと仮定しています):

appsスクリプトでは、 .GSファイルとHTMLファイルは、おおよそ以下の線に沿ってうわ

//**feed.gs** 
 
function doGet(e) { 
 
    return HtmlService 
 
     .createTemplateFromFile('my-html-file') 
 
     .evaluate(); 
 
} 
 

 
function getToken() { //use your fb app info here (and make sure this script is protected/runs as you 
 

 
    var url = 'https://graph.facebook.com' 
 
    + '/oauth/access_token' 
 
    + '?client_id=0000000000000000' 
 
    + '&client_secret=0x0x0x0x0x0x0x0x0x0x0x0x' 
 
    + '&grant_type=client_credentials'; 
 

 
    var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true}); 
 
    
 
    var json = response.getContentText(); 
 
    var jsondata = JSON.parse(json); 
 
    
 
    return jsondata.access_token; 
 
    
 
} 
 

 
function getFeed() { 
 
    
 
    var url = 'https://graph.facebook.com' 
 
    + '/your-page/feed' 
 
    + '?access_token=' + encodeURIComponent(getToken()); 
 
    
 
    var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true}); 
 
    
 
    var json = response.getContentText(); 
 
    var jsondata = JSON.parse(json); 
 
    //Logger.log(jsondata); //check this and adjust following for loop and html showFeed function accordingly 
 
    
 
    var posts = {}; 
 

 
    for (var i in jsondata) { 
 
     posts[i] = {"post":jsondata[i].message}; 
 
    } 
 
    
 
    return posts; 
 
    
 
}
<!--**my-html-file.html**--> 
 
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <base target="_top"> 
 

 
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 

 
     <script> 
 
     // The code in this function runs when the page is loaded (asynchronous). 
 
     $(function() { 
 
      google.script.run 
 
      .withSuccessHandler(showFeed) 
 
      .withFailureHandler(onFailure) 
 
      .getFeed(); //this function is back in .gs file and must return an array or object which gets auto-passed to the showFeed function below 
 
     }); 
 
    
 
     function showFeed(posts) { //parameter name must match array or object returned by getFeed in gs file 
 
      var html = ''; 
 
      for (var p in posts) { 
 
       html += '<p>' + posts[p].post + '</p>'; //instead of a string, you can build an array for speed 
 
      } 
 
      $('#feed').empty().append(html); //if you used an array for the html, you'd split it here 
 
     } 
 
     function onFailure(error) { 
 
      $('#feed').empty().append("Unable to retrieve feed: " + error.message); ; 
 
     } 
 
     </script> 
 

 
    </head> 
 
    <body> 
 
    
 
     <div id="feed"> 
 
      Loading... 
 
     </div> 
 
    
 
    </body> 
 
</html>

関連する問題