Google-Voice-PHP-API icon indicating copy to clipboard operation
Google-Voice-PHP-API copied to clipboard

It works locally and fails remotely

Open MotionDesignStudio opened this issue 10 years ago • 17 comments

This is the error I am receiving.

Fatal error: Uncaught exception 'Exception' with message 'Could not log in to Google Voice with username: [email protected]' in /mnt/stor1-wc2-dfw1/416498/627339/php.mo-de.net/web/content/farse/Google-Voice-PHP-API-master/GoogleVoice.php:69 Stack trace: #0 /mnt/stor1-wc2-dfw1/416498/627339/php.mo-de.net/web/content/farse/Google-Voice-PHP-API-master/GoogleVoice.php(204): GoogleVoice->_logIn() #1 /mnt/stor1-wc2-dfw1/416498/627339/php.mo-de.net/XXX/XXX/XXX/XXXX.php(20): GoogleVoice->getUnreadSMS() #2 {main} thrown in /mnt/stor1-wc2-dfw1/416498/627339/php.mo-de.net/XXX/XXXX/XXXXX/Google-Voice-PHP-API-master/GoogleVoice.php on line 69

MotionDesignStudio avatar Apr 14 '14 19:04 MotionDesignStudio

I had this problem today also, except I didn't test locally. If you add print_r($html); to the _logIn() function, you'll probably get a page asking you to verify your identity (see attached screenshot). You won't be able to submit the form, though, so you'll have to try something else. Maybe try logging in with links or elinks. If this is your problem, it would make sense that it works locally but not remotely.

Hope this helps! I will be forking this to add my own functions to it, so I might have to add a few lines to handle submitting the recovery email for verification. I'll reply here if I can get the author to merge my updates.

screenshot-20140422-1029

DanielMarquard avatar Apr 22 '14 14:04 DanielMarquard

@lindylex, can you please test my fork before I submit a pull request? Just pass GoogleVoice() your Gmail's recovery email address as a third argument. Let me know how it works for you.

https://github.com/danielmarquard/Google-Voice-PHP-API

DanielMarquard avatar Apr 22 '14 16:04 DanielMarquard

Danielmarquard, you are awesome. I was dreading the idea of spending hours trying to figure this out. I just do not have enough time.

I am not home. I will test this later today. I seriously hope this works. I will give you credit at the url where I created a project using this code.

Thanks, Lex

MotionDesignStudio avatar Apr 22 '14 18:04 MotionDesignStudio

I added the following to permanently delete a message. I have never requested a merge or submitted my changes before. I will give it a try.

/**
 * Delete permanently a message or conversation.
 * @param $message_id The ID of the conversation to delete.
 */

public function deleteForever($message_id) {
    $this->_logIn();

    curl_setopt($this->_ch, CURLOPT_URL, 'https://www.google.com/voice/b/0/inbox/deleteForeverMessages/');
    curl_setopt($this->_ch, CURLOPT_POST, TRUE);
    curl_setopt($this->_ch, CURLOPT_POSTFIELDS, array(
        '_rnr_se' => $this->_rnr_se,
        'messages' => $message_id,
        'trash' => 1
    ));

    curl_exec($this->_ch);
}

I added the following from above, above this line: " public function dom_dump($obj) {"

Use it like this to permanently delete a message. $gv->deleteForever($s->id);

MotionDesignStudio avatar Apr 23 '14 05:04 MotionDesignStudio

I tested it locally and it works fine. My hosting company changed something in their settings disabling my ability to upload to my website. Once I have access I will upload to test.

MotionDesignStudio avatar Apr 23 '14 05:04 MotionDesignStudio

Danielmarquard ,

I receive this error testing it remotely:

Fatal error: Uncaught exception 'Exception' with message 'Could not log in to Google Voice with username: [email protected]' in /XXX/XXX/php.mo-de.net/XXX/Google-Voice-PHP-API-master/GoogleVoice.php:88 Stack trace: #0 /XXX/XXXX/php.mo-de.net/XXXX/Google-Voice-PHP-API-master/GoogleVoice.php(223): GoogleVoice->_logIn() #1 /XXXXXXX/php.mo-de.net/XXXX.php(27): GoogleVoice->getUnreadSMS() #2 {main} thrown in /XXXXXX/php.mo-de.net/XXXX/Google-Voice-PHP-API-master/GoogleVoice.php on line 88

MotionDesignStudio avatar Apr 23 '14 19:04 MotionDesignStudio

Hey @lindylex. Sorry for my delay. :)

Can you add print_r($html) to that exception message in GoogleVoice.php? That will display the page that the script fails on. That will be helpful to both of us.

DanielMarquard avatar Apr 26 '14 10:04 DanielMarquard

Just a heads up this approach needs to updated as

value="RecoveryEmailChallenge"

no longer exists in the page and the form appears to differ as well.

boombatower avatar Sep 09 '14 07:09 boombatower

Boombatower and DanielMarquad, I printed out the html error where the exception error is located and this is what I see. It looks like Google wants me prove what city I login from. It is asking me some secirity question.

This is the line I modified to display the error.

"throw new Exception("Could not log in to Google Voice with username: PRINT HTML >> ". print_r($html)." << PRINT HTML". $this->_login);"

May you help me solve this please?
error

http://mo-de.net/d/error.png

Sorry for the huge delay. I was in hosting company hell for 7 months.

MotionDesignStudio avatar Jan 22 '15 06:01 MotionDesignStudio

[ Solution Solved ]

The problem: Google does not like less secure applications to have access to your account. When these applications try to login additional verification steps are needed. A way to get pass this is to decrease the level of security by doing the following.

  • Log into the account you are tying to use at www.google.com/voice
  • Go here: https://www.google.com/settings/security/lesssecureapps Where it say "Access for less secure apps" select "Enable".
  • Go here: https://accounts.google.com/DisplayUnlockCaptcha and click on "Continue".

That solved it for me.

Thanks for all the help, until next time.

[ This is what I created if anyone is interested in playing with it. ]

http://mo-de.net/farce/

MotionDesignStudio avatar Jan 22 '15 08:01 MotionDesignStudio

hello DanielMarquard, i found this today and this is very nice n helpful, but i have some issue with

Fatal error: Uncaught exception 'Exception' with message 'Could not parse for GALX token' in /home/anjali09/public_html/sms2/GoogleVoice.php:48 Stack trace: #0 /home/anjali09/public_html/sms2/GoogleVoice.php(110): GoogleVoice->_logIn() #1 /home/anjali09/public_html/sms2/example.php(13): GoogleVoice->callNumber('9530519517', '5558675309', 'mobile') #2 {main} thrown in /home/anjali09/public_html/sms2/GoogleVoice.php on line 48 please tell me about this and a solution.

sandhibaljeet avatar Sep 14 '16 06:09 sandhibaljeet

Look at https://github.com/xenth/Google-Voice-PHP-API It is a forked version of this repository that parses the google login page using a more robust dom method. Also look at https://github.com/marallyn/Google-Voice-PHP-API which is a fork of xenth's fork that adds a few more functions and abstractions.

marallyn avatar Sep 14 '16 11:09 marallyn

I wrote a script that uses this API set up as a cron job to run once a minute, and while it works for a little while, it seems that after enough login attempts, Google starts throwing captchas in to the mix, which causes trouble logging in. Does anyone have a solution to that, or does change account settings to allow less secure apps fix the problem?

DavidBerdik avatar Jul 25 '18 18:07 DavidBerdik

@DavidBerdik Give this a try: https://accounts.google.com/b/0/DisplayUnlockCaptcha

daviddietz-zz avatar Jul 25 '18 20:07 daviddietz-zz

@daviddietz-zz I haven't quite figured out what the link does, but I did push the "Continue" button.

DavidBerdik avatar Jul 26 '18 01:07 DavidBerdik

@DavidBerdik Unlock Gmail for a New Email Program or Service: To allow a new email program that Gmail has blocked as suspicious access to your account:

1. Have the email program or service (cron job) that has failed to access your Gmail account ready. Important: If you use 2-step authentication with your Gmail account (https://www.lifewire.com/secure-your-gmail-account-with-password-and-phone-authentication-1171958), make sure you create an application password for the new client (https://www.lifewire.com/get-a-password-to-access-gmail-by-pop-imap-2-1171882).

2. Visit the Allow access to your Google account page at Google. (https://accounts.google.com/DisplayUnlockCaptcha) Note: Log in to the desired Gmail account if prompted.

3. Click Continue.

4. Within 10 minutes of clicking "Continue," have the previously blocked email service or program (your cron job) check for new messages.

daviddietz-zz avatar Jul 26 '18 13:07 daviddietz-zz

@daviddietz-zz Okay thank you. I had to change my script to use a new Google account, and within the first 24 hours of doing so, I had to use this twice, but since then, it appears to be working without any interruptions.

DavidBerdik avatar Jul 28 '18 17:07 DavidBerdik