从 iframe 嵌入式 Facebook 应用程序获取数据

发布于 2024-08-09 10:03:02 字数 421 浏览 5 评论 0 原文

使用 iFrame,我网站上的某人可以访问他们的 Facebook 帐户,显示他们的相册列表,然后显示所选相册中的照片。

目前,当用户单击照片时,我会显示一个对话框,其中显示照片的路径。

以上所有内容都完美运行。

我的下一步是将照片的路径信息传递回我的网页,但我不确定如何执行此操作,因为我想要将数据传递到的对象位于 iFrame 之外,因此 Facebook 不知道该对象。我尝试通过我的网站上包含 iFrame 的 DOM 引用它来自上而下...

parent.client.document.getElementById("FBPhoto").setValue(photoReference);

...但这没有用。

在我的网站上将参数传递给 PHP 脚本将不起作用,因为我不想刷新网站上的页面(因为这会导致用户丢失数据)。

Using an iFrame, someone on my website can access their Facebook account, display a list of their photo albums, and then display photos from selected albums.

At the moment, when the user clicks a photo, I display a dialog box that shows the photo's path.

All of the above works perfectly.

My next step is to pass the photo's path info back to my web page, but I'm not sure how to do that because the object, to which I want to pass the data, is outside of the iFrame and therefore unknown to Facebook. I tried going top-down by referencing it through the DOM that contains the iFrame on my website...

parent.client.document.getElementById("FBPhoto").setValue(photoReference);

...but that didn't work.

Passing the argument to a PHP script, on my site, won't work because I don't want to fresh the page on my site (since that would cause the user to lose data).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清浅ˋ旧时光 2024-08-16 10:03:02

从你提供的内容来看,你的 JS 可能是错误的。

做这样的事情可能会得到你需要的值:

var photoReference = window.frames["iframe-name"].document.getElementById("FBPhoto");

然后你需要将它分配给某些东西:

MyObject.setValue(photoReference);

注意: window.frames["iframe-name"].document.getElementById("FBPhoto") 将返回名为 #FBPhoto 的 DOM 元素,因此将是一大块 HTML。您的 setValue() 方法可能不希望出现这种情况。

我建议您尝试在 Firefox 中使用 Firebug,它允许您将 photoReference 的值转储到控制台以查看返回的内容。

From what you've provided it looks like your JS might be wrong.

Doing something like this might get you the value you need:

var photoReference = window.frames["iframe-name"].document.getElementById("FBPhoto");

Then you need to assign it to something:

MyObject.setValue(photoReference);

Note: window.frames["iframe-name"].document.getElementById("FBPhoto") will return the DOM element called #FBPhoto and will therefore be a big chunk of HTML. Your setValue() method might not be expecting that.

I suggest you try running your script in Firefox with Firebug installed, which will allow you to dump the value of photoReference to the console to see what you're getting back.

懷念過去 2024-08-16 10:03:02

Doy...我意识到,由于 Facebook 连接在专用的 iFrame 中运行,因此重定向该框架不会有问题,因为无论如何都没有理由让它保持打开状态。

对于任何感兴趣的人,这就是我所做的...

  1. PHP(在index.php 内部)显示相册照片。

  2. PHP 还使用 href 标签包围每个 img 框架。

  3. 该链接指向一个 PHP 文件(在我的网站上),并包含一个带有大版本照片位置的参数(因为我的应用程序显示缩略图)。类似于: "< a href="pathToMySite/get-photo.php?photopath=facebook's path ">

  4. 当用户单击所需的照片时,其相应的链接将调用 get-photo.php(在我的网站上)并传递照片的路径。

  5. get-photo.php 然后将对我的网站的主 JS 文件的引用插入到文档头中,并将脚本插入到 HTML 文档的正文中。

  6. 该脚本调用 JS 获取照片函数,并传递从运行 Facebook 应用程序的嵌入式 iFrame 接收的路径参数。

  7. JS 函数关闭 iFrame(因为那时我已经不再使用 Facebook)并从 Facebook 获取照片。

Doy... I realized that since the Facebook connection was running in a dedicated iFrame, it wouldn't be a problem to re-direct that frame because there was no reason to leave it open anyhow.

For anyone interested, here's what I did...

  1. The PHP (inside of index.php) displays the album photos.

  2. The PHP also surrounds each img frame with href tags.

  3. The link points to a PHP file (on my website) and includes an argument with the location of the large version of the photo (since my app is displaying thumbnails). Something like: "< a href="pathToMySite/get-photo.php?photopath=facebook's path ">

  4. When the user clicks on the desired photo, its respective link calls get-photo.php (on my site) and passes the path for the photo.

  5. get-photo.php then inserts a reference to my website's main JS file into the document head, and inserts a script into the body of the HTML document.

  6. The script calls a JS fetch-photo function, and passes the path argument that it received from the embedded iFrame that was running the Facebook app.

  7. The JS function closes the iFrame (since I'm done with Facebook at that point) and grabs the photo from Facebook.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文