Does anyone know how this code is not going to work anymore, or why all my services 2 methods come back invalid?
//presume correct api_key, nonce etc
$hash = hash_hmac('sha256', $timestamp .';mysite.com;'. $nonce .';'.'vote.setVote', $api_key, 0);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, 'http://imobileintervals.com/services/json');
//prepare the field values being posted to the service
$data = array(
'method' => 'vote.setVote',
'hash' => $hash,
'domain_name' => 'mysite.com',
'time_stamp' => $timestamp,
'domain_time_stamp' => $timestamp,
'nonce' => $nonce,
'api_key' => $api_key,
'sessid' => $sessid,
'content_type' => 'node',
'content_id' => $myNID,
'vote_value'=> $voteVal,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
This was working under services version 0.15. With services 2 dev I get error true, invalid method vote.setVote
I also get invalid method for any other method I try to run. I get invalid if I turn off authentication.
I'd revert to services 0.15 but what i really need now is to use node.save, and I can't get that working under 0.15, so I'm trying to get services 2 going...
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 663744.patch | 1.97 KB | gdd |
| #1 | 663744.patch | 1.89 KB | gdd |
Comments
Comment #1
gddServices recently changed some of its data structures in such a way that the JSON Server module broke. The attached path should fix this issue.
Comment #2
ilo commentedThanks heyrocker for the patch. I was about to commit, but then I realized, does this patch force everyone using json_server to update to services-6.x-2.x?
Comment #3
ransomweaver commentedThis fixes my issues. Thank you very much!
Comment #4
gddilo you are right, good catch. I have attached a new patch which should address that issue, although someone should test it under the older version (I don't have it installed anywhere right now.)
Comment #5
ilo commentedOh, thanks heyrocker for rerolling it. At first sight I saw the 'services_strip_hashes' function being called, and that one is not in earlier 1.x versions, so I think I'll put some "ifs" wrapping the changes. Anyway, afaik, services_strip_hashes is already called by services_get_methods() call, but need to double check.
edit: s/if/"ifs"/
Comment #6
skyredwangconfirmed: #4 patch fixes the problem
Comment #7
burningdog commentedPatch at #4 fixes my problem too (after I'd already rolled a patch, then saw the exact patch was already here! Thanks @heyrocker).
@ilo, you asked, "Does this patch force everyone using json_server to update to services-6.x-2.x?"
Yes, it does, since the data structure has been updated. I'd suggest the following to make sure functionality doesn't break for people using Services 6.x-0.15: make the current 6.x-1.x-dev release to be 6.x-1.x-beta and mark it as "other releases". Add a README to say, "Works with Services 6.x-0.15".
Then patch JSON Server with the patch at #4, and make a new recommended release: 6.x-2.x-dev. In the README (and the release notes) add something to say, "Works with Services 6.x-2.x".
Comment #8
sumitk commentedPatch in #4 is working great .... thanks heyrocker
Comment #9
burningdog commentedMarking critical, as the out-of-the-box implementation doesn't work.
Comment #10
irishgringo commentedany word on when JSON SERVICES will be released that does not need a patch? will work out of the box?
Comment #11
burningdog commentedThat's up to @ilo. @ilo, is there anything stopping you from patching JSON Server and following the release suggestions in #7?
Comment #12
burningdog commentedActually, I guess that's up to @andremolnar?
Comment #13
burningdog commentedOr Steve McKenzie? If nothing is stopping this from getting in...can you please commit it?
Comment #14
ilo commentedNo real real stoppers here, but all people using the previous (1.x) services implementation. I'll follow suggestions by Rober #7 and commit this.
Comment #15
burningdog commentedHooray! Rober thanks you :)
Comment #16
ilo commentedSo.. Thanks again 'Rober'.. Heyrocker, thanks you too.. Looks like Steve already committed it silently a few days ago, I just finished the release and readmes's stuff. Need someone to verify this but I'll mark as fixed once for all.
Thank you all!
Comment #18
jaypark commentedi'm using (newly installed, not an upgrade)
JSON server 6.x-2.0-alpha2
Services 6.x-2.2
services/json returns > { "#error": true, "#data": "Invalid method " }
i verified that alpha2 includes the patch in this thread... but what other bugs could cause this issue?
services calls, eg, admin/build/services/browse/node.get, work ok but not services/json.
Comment #19
pwaterz commentedThe problem is not with JSON Server module. PHP made some changes to the json parsing engine some where between 5.2.6 and 5.2.10. Make sure to wrap all of post requests in double quotes and that should solve you problem.
Like so...
<? $data = array(
'method' => '"vote.setVote"',
'hash' => '"'.$hash.'"',
'domain_name' => '"mysite.com"',
'time_stamp' => '"'.$timestamp.'"',
'domain_time_stamp' => '"'.$timestamp.'"',
'nonce' => '"'.$nonce.'"',
'api_key' => '"'.$api_key.'"',
'sessid' => '"'.$sessid.'"',
'content_type' => '"node"',
'content_id' => '"'.$myNID.'"',
'vote_value'=> '"'.$voteVal.'"',
);?>
Comment #20
msielskiIs there any way to have the module account for this change in PHP, referenced in #19? First, for people with clients in the wild (mobile apps etc) where changing the clients to add double quotes may not be easy to do and second, because it's kind of a hack to have to add double quotes to data for this to work properly. That is, it's a workaround which isn't immediately obvious.
Comment #21
rbryer commentedNot sure that some of this post is correct. The basic installs for these modules are broken.
I am running PHP 5.2.6
I have installed a clean Service 6.x-2.4
I have installed a clean JSON-Server 6.x-2.0-alpha2
All enabled and permissions set. If I click on the link to mysite/services/json I get
{ "#error": true, "#data": "Invalid method " }
So are you saying that this module is not compatible with PHP 5.2.6 ?? That should be stated on the main page (which currently states that its not compatible with 5.3.x)
I have also tried this with the latest dev version of JSON-Server but that also fails
Comment #22
lelizondo commentedI'm using PHP 5.2.10 and is also failing. Tried both versions of Json, 2.0-alpha2 and 2.x-dev
I'll try to downgrade to PHP 5.2.5
Comment #23
andybounce commentedCan confirm a fail on this side too, using both alpha and dev versions on php 5.2.17. Can't get it to work with double quotes either.
Even a straight POST access of the /services/json url spits back an invalid method.
Comment #24
lelizondo commentedDowngrading to PHP 5.2.5 using Ubuntu 10.10 is just a nightmare. Don't do it!
Comment #25
pwaterz commentedIt's not that hard to downgrade...check out http://randyfay.com/node/63 and make sure to read the comments
Comment #26
lelizondo commentedThe problem with that guide, and pretty much with any other guide I could find is that is a downgrade from 5.3 to 5.2.10 (I think is 10) which is the version that comes with karmic. Downgrading to 5.2.5 is really hard because you'll end up with a huge mess with dependencies. If I remember correctly, it was Ubuntu 8.04 the version that comes with 5.2.4 or 5.2.5, if my math is correct, that's about 3 years old.
The other solution is compile from source which is not a bad choice, but again, I wouldn't recommend to install Apache & MySQL using aptitude and then compile PHP, in my case, as I mentioned before, it was a nightmare.
The solution was to use REST instead of JSON, but even REST needs a couple of patches to work properly. For GET requests, REST can show the result as json or xml, whatever fits your needs, which is cool, for POST requests that's another story.
Comment #27
ransomweaver commentedI just had to move a Drupal 6 services 2.4 setup to a new host running php 5.3.2, and the json server broke. I am unable to upgrade to services 3 presently because I need to use AMFPHP server also, but to get things working again the double-quoting in #19 did the job.