1

我读过您可以制作显示Facebook供稿的Google Apps脚本,然后将其嵌入到Google网站中,但我找不到有关如何操作的更多信息,而且我无法确定它我自己。如何在新的Google协作平台中嵌入Facebook供稿(使用Apps脚本)?

当我试图使Google Apps脚本的Web应用程序与Facebook的饲料我得到这样的错误:

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

这是抄袭“脸谱的Javascript SDK”和“换页”从Facebook开发成HTML文件并将其部署为Web应用程序。我收集它与Apps脚本如何沙箱代码有关,但我不知道我必须在这里做什么。

对于这个问题,即使我尝试使用某些静态HTML制作更简单的Apps脚本,当我尝试将它从Drive嵌入到网站中时,我收到一条错误消息“某些选定项目无法嵌入”。

回答

0

新的谷歌网站现在所做的支持嵌入应用程序脚本(确保部署的应用程序脚本的Web应用程序,设置正确的权限,并使用/ EXEC网址,而不是你的/开发一个嵌入)。

我发现我无法使用Facebook SDK作为沙盒视频。我使用iframe解决方案代替视频,但也许你可以尝试类似这样的Feed(我假设你已经在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>

相关问题