PHP 上的简单但高级的 XML-RPC?
我正在尝试在我的项目中使用 Opensubtitles API,但我无法使其正常工作。我使用的是一个名为 Ripcord 的包装器,它非常简单且易于使用,但它不支持一切。使用方法 LogIn 很容易,但是当 搜索字幕,我无法使其工作。
这是我的简单代码:
include('ripcord.php');
$client = ripcord::client('http://api.opensubtitles.org/xml-rpc');
$token_from_login = $client->LogIn('username','password','lang','useragent'); //works fine
$get = $client->SearchSubtitles($token_from_login,array('query'=>$search)); //doesn't work
问题一定是 Ripcord 不支持数组。因此,我正在寻找其他方式来轻松拨打电话。
我是 XML-RPC 的新手,所以我希望获得一些建设性的帮助,因为它似乎是制作 API 的一种流行方式。我基本上需要一个 XML-RPC 调用的好例子。我无法理解 PHP 手册。如果没有包装器/类就相当简单,则不需要包装器/类。
马蒂·莱恩
I'm trying to use the Opensubtitles API in my project, but I just can't make it work right. I'm using a wrapper called Ripcord, which is ultimately simple and nice to use, but it doesn't support everything. It's easy to use the method LogIn with it, but when searching for subtitles, I cannot make it work.
Here's my code in all its simplicity:
include('ripcord.php');
$client = ripcord::client('http://api.opensubtitles.org/xml-rpc');
$token_from_login = $client->LogIn('username','password','lang','useragent'); //works fine
$get = $client->SearchSubtitles($token_from_login,array('query'=>$search)); //doesn't work
The problem must be the the fact that Ripcord doesn't support array. So I'm looking for alternative ways to make calls with ease.
I'm new to XML-RPC so I wish for some constructive help as it seems to be a popular way to make API. I basically need a good example for XML-RPC calls. I cannot understand the PHP's manual. A wrapper/class is not necessary, if it's fairly simple without a one.
Martti Laine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我是 Ripcord 的作者,它确实支持数组,因为它使用 PHP 的 xmlrpc_encode 来自动将其转换为“struct”类型。
但是,您的脚本使用未声明的变量 $search,该变量在此脚本中未填充任何内容。假设您有一个填充此变量的工作脚本,您可能需要检查从服务器获得的响应。调用方法后,您可以通过 $client->_response 属性访问它。要查看客户端发出的确切 xml-rpc 请求,请检查 $client->_request 属性。
不幸的是,我无法进一步检查您的代码,因为 opensubtitles.org 现在似乎有一些问题。
I'm the author of Ripcord, it does support arrays, as it uses PHP's xmlrpc_encode which converts it automatically to the 'struct' type.
However your script uses an undeclared variable $search, which isn't filled with anything in this script. Assuming you have a working script which does fill in this variable, you might want to check what response you are getting from the server. You can access that through the $client->_response property, after calling a method. To see the exact xml-rpc request the client made, check the $client->_request property.
Unfortunately I could not check your code further, since opensubtitles.org seems to have some problems right now.
尝试包含 Zend Framework 的 xml-rpc 客户端 - 我认为这不会有太大麻烦。它构建得非常巧妙,我认为它可以解决数组的问题。
Try to include the Zend Framework's xml-rpc client - I don't think it would be much of a hassle. It is very neatly built and I think it will solve the problem with arrays.