albeebe / PHP-FindMyiPhone

PHP class to locate, play sounds, and lock iOS devices
Other
81 stars 48 forks source link

Stopped working #6

Open kristianolofsson opened 7 years ago

kristianolofsson commented 7 years ago

Trying to use the find my iPhone class but gets error about multiple slashes. What's wrong?

beinnlora commented 7 years ago

probably the same as issue #4 see changes in code in #5

We'll need more detail than that - what OS? What PHP version? What's the error message exactly (copy and paste here)? What code are you using to call the class?

kristianolofsson commented 7 years ago

Using osx and php version 5.6.27

In using a big set of code but even using your simple code from read me to print devices provides the error.

This did work last week.

beinnlora commented 7 years ago

We will still need to see the error message to help you. You need to overwrite your class.findmyiphone.php with the patched version in #5.

@kristianolofsson Can you create a file called "test.php" with the simple contents below (replace with your icloud username and password), then copy and paste the output

<?php
    include ("class.findmyiphone.php");
    $fmi = new FindMyiPhone("icloud_username", "icloud_password", true);
    $fmi->printDevices();
?>
jeffersonblizz commented 7 years ago

Hi I use this part of the q code changed as follows

If (isset ($ headers ['X-Apple-MMe-Host'])) { $ This-> host = $ headers ['X-Apple-MMe-Host']; $ This-> scope = $ headers ['X-Apple-MMe-Scope']; Throw new FindMyiPhoneException (true); } I would change what there in this code?

Follow the link to my complete code http://pastebin.com/FhHQKJF0

beinnlora commented 7 years ago

@Halyspectro you posted this question already in #5. See #5 for an answer.

jeffersonblizz commented 7 years ago

Sorry, thank you !!!

odelma commented 7 years ago

Hmm, cannot seem to get it working with the proposed changes. The simple printDevices with debug=TRUE actually prints everything (without debug=TRUE just gives the errors) but with these errors:

Notice: Undefined offset: 1 in /home/pi/scripts/class.findmyiphone.php on line 260
Notice: Undefined offset: 1 in /home/pi/scripts/class.findmyiphone.php on line 260
Notice: Undefined variable: request in /home/pi/scripts/class.findmyiphone.php on line 246
* getaddrinfo(3) failed for fmipmobile.icould.com:443
* Couldn't resolve host 'fmipmobile.icould.com'
* Closing connection #0

246: $arrHeaders["Content-Length"] = strlen($request); 260: list ($key, $value) = explode(': ', $line);

there should not be any modifications other than those on the pull request. Funny thing is that in Domoticz the presence detection script is working fine with: curl -s -X POST -L -u '" .. credentials.username .. ":" .. credentials.password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://fmipmobile.icloud.com/fmipservice/device/" .. credentials.username .."/initClient"

I noticed the headers are a bit different but that should not matter as these here work for you? Any ideas what could be wrong?

edit: without debug and php error_reporting = 0 it gives:

* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
* Connection #0 to host fmipmobile.icloud.com left intact
* Closing connection #0
* getaddrinfo(3) failed for fmipmobile.icould.com:443
* Couldn't resolve host 'fmipmobile.icould.com'
* Closing connection #0
beinnlora commented 7 years ago

typo in your header fmipmobile.icould.com should be fmipmobile.icloud.com

looks like you've replaced the header manually, with a typo in some places and not others.

The code can be tidied up somewhat now there is no need to insert a custom endpoint url each call/ The URL is static. This would prevent such errors.

odelma commented 7 years ago

Guess this means I'm pretty tired (that is what I suspected but just couldn't see it)... :smile: Strangest thing is that I thought I changed it on the first instance only and then just copied. Somehow the authentication was still correct. Well, maybe I changed it separately first.

Thanks!

jeffersonblizz commented 7 years ago

@beinnlora Hi, there are errors in this snippet of my code. On line 140. It says 1 parameter is missing to use sprintf, before putting $ this-> scope and now what to put?

Warning: sprintf(): Too few arguments in FindMyiPhone.php on line 129

CURLOPT_URL => sprintf ("https: //% s / fmipservice / device /% s /% s", $ this-> host, $ method), Follow the code link after the changes proposed by you http://pastebin.com/7eCWBawi

beinnlora commented 7 years ago

@Halyspectro this is not an issue with the library, but a general PHP coding issue. I don't think this is the best place to support you in fixing your code, but I will try.

You need to understand the error message and interpret its use in your code. Here, the "%s" inside the quotes will be substituted with the values of the variables ('Arguments') outside the quotes. See this explanation: http://www.w3schools.com/php/func_string_sprintf.asp

You have three %s inside the quotes, https: //% s / fmipservice / device /% s /% s

and just two variables/arguments outside the quotes: $ this-> host and $ method

hence the error message saying 'too few arguments'

The old Apple iCloud service was accessed from a URL like "https://Apple_MMe_Host/fmipservice/device/Apple_MMe_Scope/playSound"; where the values for MMe_host and MME_Scope needed to be replaced with whatever Apple sent you when you first authenticated/logged in.

The new Apple iCloud service URL looks like this: "https://fmipmobile.icloud.com/fmipservice/device/myusername@me.com/playSound"

You can see it doesn't need MMe_Host and MMe_scope any longer, but does need your Apple username.

You therefore need to change any CURLOPT_URL in your code to create a URL in the new format.

For flexibility in case the url changes again, we can define the HOST in a variable (the "fmipmobile.icloud.com" bit of the address) - also to save us typing it out each time and making mistakes.

The whole URL for triggering an event, e.g. "playSound" is something like: "https://fmipmobile.icloud.com/fmipservice/device/myusername@me.com/playSound" which you would make up from your variables: http:// $this->host /fmipservice/device/ $username $method

Therefore in your code we need to make THREE substitutions in your url - to insert the HOST, USERNAME and METHOD in the right places.

so each CURLOPT_URL should look a little like this: CURLOPT_URL => sprintf ("https://%s/fmipservice/device/%s/%s", $this->host, $username, $method),

each %s inside the quotation marks is replaced in turn with the three variables you define outside the quotation marks.

Any further questions I would ask you to please raise on a general PHP discussion forum, as it is not really an issue with the library. Try stackexchange.com

good luck

kristianolofsson commented 7 years ago

Thanks a lot! Working fine.

I did find though that the "listdevices" function was removed. I kinda used that so please add it back.

Kristian Olofsson 0736-336291

On 13 Jan 2017, at 20:23, beinnlora notifications@github.com wrote:

@Halyspectro this is not an issue with the library, but a general PHP coding issue. I don't think this is the best place to support you in fixing your code, but I will try.

You need to understand the error message and interpret its use in your code. Here, the "%s" inside the quotes will be substituted with the values of the variables ('Arguments') outside the quotes. See this explanation: http://www.w3schools.com/php/func_string_sprintf.asp

You have three %s inside the quotes, https: //% s / fmipservice / device /% s /% s

and just two variables/arguments outside the quotes: $ this-> host and $ method

hence the error message saying 'too few arguments'

Previously the FindMyiPhone class required the values X-Apple-MME-host and X-Apple-MME-Scope to create the correct URL to call.

The recent change to the Apple service means you no longer need to supply these two X-Apple-MME variables each time you call the Apple API url. You therefore need to change any CURLOPT_URL in your code, to a new URL that doesn't include the MMe-Host and MMe-Scope, and instead includes your iCloud username.

For flexibility in case the url changes again, we can also define the HOST in a variable (the "fmipmobile.icloud.com" bit of the address) - also to save us typing it out each time and making mistakes.

The whole URL for triggering an event, e.g. "playSound" is something like: "https://fmipmobile.icloud.com/fmipservice/device/myusername@me.com/playSound" which you would make up from your variables: http:// $this->host /fmipservice/device/ $username $method

Therefore in your code we need to make THREE substitutions in your url - to insert the HOST, USERNAME and METHOD in the right places.

so each CURLOPT_URL should look a little like this: CURLOPT_URL => sprintf ("https: //%s/fmipservice/device/%s/%s", $this->host, $username, $method),

each %s is replaced in turn with the three variables you define outside the quotation marks.

Any further questions I would ask you to plase raise on a general PHP discussion forum, as it is not really an issue with the library. Try stackexchange.com

good luck

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

beinnlora commented 7 years ago

@kristianolofsson public function printDevices() still exists... No functions have been removed from the library in the latest commit (Jan 2016)... unless some element of the API has changed that we have no control over..

jeffersonblizz commented 7 years ago

@beinnlora @albeebe I found out what was happening that I could not verify if my page took the value or not of the Exception I'm a little lay in php but I'm good in java and I managed to debug my code to check the value of my variables. My focus on using FindMyIphone.php is just checking if the apple id is real. Okay, let's go there before the update I would do the following to return true to my page that was requesting the class IMF I would do an if that way

If (isset ($ headers ['X-Apple-MMe-Host'])) { $ This-> host = $ headers ['X-Apple-MMe-Host']; $ This-> scope = $ headers ['X-Apple-MMe-Scope']; Throw new FindMyiPhoneException (true); } Else { Throw new FindMyiPhoneException (false); }

And I took this value this way and then I saw that it was a real apple id. If ($ e-> getMessage () == true) { Header ("Location: ./map/index.php"); } Else { Header ('Location:'. $ _ SERVER ['HTTP_REFERER']. '? Error = error'); } But now there's no way to check with these headers anybody has any idea which of the $ headers I use now to check if it's a valid id? I know I already seem to be bothering but the lack of experience and documentation on the api I have only recourse to you, if someone has some page for me to study more about the api and to be able to send please I would be grateful.