在简单的 PHP 社交媒体课程中使用 CURL 和 FQL
我正在构建一个简单的 PHP 类,它允许您输入 twitter 用户名、要加载的推文数量、facebook id、要加载的状态数量以及访问令牌,然后检索您的用户数据(姓名、个人资料图片等)。 )和指定数量的推文/状态。
我通过使用 cURL 调用 URL 并使用 PHP 内置的 json_decode() 函数将其解析为对象来检索 JSON 数据。
我的问题是这样的 - 我可以通过将用户名传递到正确的网址(例如 http ://twitter.com/users/user.json),但所有 facebook 数据都返回 NULL。我想我知道问题所在 - 我正在使用 FQL,因此调用如下 URL:
这似乎会将您重定向到构建的文件(而 twitter 直接链接到正确的文件)。
有人知道我如何才能完成这项工作吗?我更愿意使用FQL,因为我已经对此有了更多的了解,但如果不可能的话,
我可以提供您需要的任何其他详细信息。
I'm building a simple PHP class that will allows you to enter your twitter usename, number of tweets to load, facebook id, number of statuses to load, and access token and then retrieves your user data (name, profile pic, etc.) and the specified number of tweets/statuses.
I'm retrieving the data as JSON by calling a URL using cURL and using PHP's built in json_decode() function to parse it into an object for me.
My problem is this - I can retrieve all the twitter data perfectly fine by passing the username to the correct url (e.g. http://twitter.com/users/user.json) but all of the facebook data is returning NULL. I think I know the problem - I am using FQL so am calling URLs like:
which seems to then redirect you to the built file (whereas twitter is linked directly to the correct file).
Does anybody know how I can make this work? I would prefer to use FQL as I've got my head around it a bit more but if it's not possible it's not too big a deal for me to change.
I can provide any other details you need
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的语法看起来非常好,因此您传递访问令牌的方式可能存在问题。
我只是看了一下我编写的一些代码,我传递的是应用程序 ID 和应用程序密钥,而不是访问令牌。自从我不久前编写该代码以来,我不确定是否会有所不同,但可能会。
如果您使用 PHP,则可以使用适用于 Facebook 的 PHP SDK。这将使您编写稍微不那么冗长的代码,从而更容易维护。您可以在这里找到它:http://developers.facebook.com/docs/sdks/
我使用它来调用 FQL 查询:
根据您想要执行的操作,您还可以使用 Graph API 来获取数据。在示例中,您使用的 Graph API 可能会更简单。但如果您想获取复杂的数据,那么 FQL 会更好。
Your syntax looks perfectly fine, so chances are that there might be an issue with the way you are passing in the access token.
I just look a look at some code I had written, and I'm passing in app ID and app secret, not the access token. I'm not sure if makes a difference or not since I wrote that code a while ago, but it might.
If you are using PHP, you can use the PHP SDK for Facebook. This will let you write slightly less verbose code which will be easier to maintain. You can find it here: http://developers.facebook.com/docs/sdks/
Using it I write this to call FQL queries:
Depending on what you are trying to do you can also use the Graph API to get data. In the example you are using the Graph API might be simpler. But if you are trying to get complicated data then FQL would be better.