Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in connecting to telegram api #33

Closed
vahidvdn opened this issue Jan 10, 2017 · 14 comments
Closed

Problem in connecting to telegram api #33

vahidvdn opened this issue Jan 10, 2017 · 14 comments

Comments

@vahidvdn
Copy link

Hi there. After struggling for some days, still I can not connect to telegram.
I installed dependencies by composer. Running the main index.php in the project, give me this error:

{"ok":false,"error_code":404,"error_description":"Invalid token provided"}

I read the docs and changed the codes:

$MadelineProto = new \danog\MadelineProto\API();
$MadelineProto->update_settings($settings);
$number = '+989380597197';
$sentCode = $MadelineProto->phone_login($number); // Send code
var_dump($sentCode);

$settings is the array that provided in the docs. I just changed api_id and api_hash to my own.

The result is this and nothing happened:

MTProto:        	Istantiating DataCenter...
MTProto:        	Loading RSA key...
RSA:            	Istantiating \phpseclib\Crypt\RSA...
RSA:            	Loading key...
RSA:            	Computing fingerprint...
RSA:            	Generating BigInteger object for fingerprint...
MTProto:        	Translating tl schemas...
TL:             	Loading TL schemes...
TL:             	Translating objects...
TL:             	Translating methods...
TL:             	Translating objects...
TL:             	Translating methods...
MTProto:        	Switching to DC 2...
DataCenter:     	Connecting to DC 2 (main server, ipv6)...

Any idea?

@danog
Copy link
Owner

danog commented Jan 10, 2017

$MadelineProto = new \danog\MadelineProto\API();
$MadelineProto->update_settings($settings);
$number = '+989380597197';
$sentCode = $MadelineProto->phone_login($number); // Send code
var_dump($sentCode);

$MadelineProto->update_settings($settings); is absolutely unnecessary
You also must not run index.php but testing.php, as described in the docs.
The log you provided is incomplete, so I can't do anything for you.
Try resetting the repo, reading the docs once again and editing testing.php to understand how MadelineProto works.

@danog danog closed this as completed Jan 10, 2017
@vahidvdn
Copy link
Author

vahidvdn commented Jan 11, 2017

Thanks.

First of all, testing.php is requiring some other php files, like web_data.php and number.php that doesn't exist in the root of the project.

When I run testing.php without any change, It gives me the below message:

Deserializing MadelineProto from session.madeline...

I just copied the first part of this file and added the number manually:

<?php

require_once 'vendor/autoload.php';
$settings = [];

$MadelineProto = new \danog\MadelineProto\API($settings);
    
$number = '+989380597197';
$checkedPhone = $MadelineProto->auth->checkPhone(// auth.checkPhone becomes auth->checkPhone
    [
        'phone_number'     => $number,
    ]
);
\danog\MadelineProto\Logger::log($checkedPhone);
$sentCode = $MadelineProto->phone_login($number);
\danog\MadelineProto\Logger::log($sentCode);

// Actually this line never runs:
echo 'Enter the code you received: ';
?>

That gives me the result that I mentioned in the end part of my question.
I really don't know what to do, as I read the docs again and wasn't be able to get started.

Any idea?

@danog
Copy link
Owner

danog commented Jan 12, 2017

testing.php is requiring some other php files, like web_data.php and number.php that doesn't exist in the root of the project

That is normal, you're supposed to create them manually and insert the $number (number.php), the bot $token (token.php) or some additional $settings (web_data.php).

To solve the problems you mentioned, try with the latest version, please.

@vahidvdn
Copy link
Author

To solve the problems you mentioned, try with the latest version, please.

I just downloaded the repo about a few days ago. I think I have some problems for running this library.
Does my mentioned code is wrong? (Which I add the $number manually)

Is there any kind of simplest code for this library just for getting started? (For example, setting a $number manually and telegram would send a key to his telegram.)

@danog
Copy link
Owner

danog commented Jan 13, 2017

I just downloaded the repo about a few days ago

Please download the latest version, it has lots of bugfixes.

The code you sent is correct.

testing.php is the simplest code available, and does exactly what you described.

@vahidvdn
Copy link
Author

vahidvdn commented Jan 13, 2017

I did it, but no difference. Again the same problem :(

This time I tested this code:

<?php

require_once 'vendor/autoload.php';
$settings = [];

$MadelineProto = new \danog\MadelineProto\API($settings);
$number = '+989380597197';
$sentCode = $MadelineProto->phone_login($number); // Send code
var_dump($sentCode);

Again, It's just printing these:

MTProto:        	Istantiating DataCenter...
MTProto:        	Loading RSA key...
RSA:            	Istantiating \phpseclib\Crypt\RSA...
RSA:            	Loading key...
RSA:            	Computing fingerprint...
RSA:            	Generating BigInteger object for fingerprint...
MTProto:        	Translating tl schemas...
TL:             	Loading TL schemes...
TL:             	Translating objects...
TL:             	Translating methods...
TL:             	Translating objects...
TL:             	Translating methods...
MTProto:        	Switching to DC 2...
DataCenter:     	Connecting to DC 2 (main server, ipv6)...

@danog
Copy link
Owner

danog commented Jan 13, 2017

Refer to #36 pls

@vahidvdn
Copy link
Author

@danog Still no way :(
Is it possible for you to check the codes by team viewer?

@vahidvdn
Copy link
Author

vahidvdn commented Jan 17, 2017

Refer to #36 pls

Finally this solved my problem. I changed this:

$this->ipv6 = strlen($google) > 0;

To:

$this->ipv6 = false;

Thank you so much ❤️

@danog
Copy link
Owner

danog commented Jan 17, 2017

Gr8, but that is not a fix, it's a workaround.
Please pull the latest version (there's a fix for ipv6), remove all serialized madeline files and try again.
I'm here if you encounter any other error.

@randomhydrosol
Copy link

@danog Ohaiy

@randomhydrosol
Copy link

@anupritaisno1 How are you?

@ttodua
Copy link

ttodua commented Aug 11, 2017

@danog
I cant understand, why you wont create a config.php file in the root of the project, where we could put our 'token','number', 'api_has' etc...
We have to manually search for files and other annoying ways to hardcode that variables and even create non-documented files (token.php or etc)..

just please, create initial examples of them (config.php and token.php ), that will save our hours...

@danog
Copy link
Owner

danog commented Aug 11, 2017

No. You're supposed to use your brain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants