Using the Facebook REST API PHP client library, it seems wise to wrap calls in try{} thus:
require('facebook.php');
$fb = new Facebook($fbApiKey, $fbSecret);
try {
$result = $fb->api_client->some_api_method(...);
} catch (FacebookRestClientException $e) {
// now what?
}
But I'm not sure what to do with the exception, e.g. to find out what went wrong or to write a sensible message to the error log. Is there documentation for these exceptions somewhere?
After examining the code and some example exceptions, I think $e is an object looking something like this:
(
[message:protected] => An error message string
[string:Exception:private] => Don't know
[code:protected] => A numerical error code
[file:protected] => File here the exception was thrown
[line:protected] => Line where the exception was thrown
[trace:Exception:private] => A PHP debug_backtrace() result
[previous:Exception:private] => Don't know
)
Related
How to get the whatsapp password using the whatsapp api?
I am still learning on using the api and have no idea to use it. I'am using sublime code editor for the code. Below is the sample code that I receive from one of the tutorials.
require_once('Chat-API/src/Registration.php');
username = "6012xxxxxxx";
$debug = true;
// Create a instance of Registration class.
$r = new Registration($username, $debug);
$r->codeRequest('sms'); // could be 'voice' too`
When I execute it, I receive this error:
Array ( [cc] => 60 [in] => 6012xxxxxxx [lg] => en [lc] => MY [id] => 蜀��|#b�պ�`���x [token] => IAW+aljx1hbtx0Vh/sqxJmKytyc= [mistyped] => 6 [network_radio_type] => 1 [simnum] => 1 [s] => [copiedrc] => 1 [hasinrc] => 1 [rcmatch] => 1 [pid] => 5138 [rchash] => 6557f1fa8776a69cc3427a6196467690cb85cc651b36cc7be02062470a72a742 [anhash] => 3c24581d24189c24a487cae2ef84d1c3 [extexist] => 1 [extstate] => 1 [mcc] => 502 [mnc] => 000 [sim_mcc] => 502 [sim_mnc] => 000 [method] => sms ) stdClass Object ( [login] => 6012xxxxxxx [status] => fail [reason] => old_version )
Fatal error: Uncaught exception 'Exception' with message 'There was a problem trying to request the code.' in C:\xampp\htdocs\tutorial\whatsapp-api\Chat-API\src\Registration.php:316 Stack trace: #0 C:\xampp\htdocs\tutorial\whatsapp-api\requestCode.php(33): Registration->codeRequest('sms') #1 {main} thrown in C:\xampp\htdocs\tutorial\whatsapp-api\Chat-API\src\Registration.php on line 316
I tried to use Wart application as well but still unable to get the password with the error of bad_token
Is there any other functions or application that I need to add. Is there also a good tutorial or video for this?
I also tried this lib, but got "fail [reason] => old_version". This library is unsupported since 10 Aug 2016. So I think it won't be working.
Try this one :
in src/Constants.php on line 22, change into
const WHATSAPP_VER = '2.17.242';
in src/Constants.php on line 27, change into
const WHATSAPP_USER_AGENT = 'WhatsApp/2.17.242 Android/4.3 Device/Xiaomi-HM_1SW';
in src/token.php on line 10, change into
$classesMd5 = 'ziYneeSZm5qExsEFX/AoMQ=='; // 2.17.242
Hope this helps.
https://github.com/tgalal/yowsup/issues/1905
I have changed the value of the constant variables in the file
src/Constants.php :
const WHATSAPP_VER = '2.18.371';
const WHATSAPP_USER_AGENT = 'WhatsApp/2.18.371 Android/4.3 Device/Xiaomi-HM_1SW';
and in the file src/token.php
$classesMd5 = 'sdGH+cA0CQfRGvQVnhZWDw==';
After that, I don't get an old_version message.
Try this one:
Open: https://coderus.openrepos.net/whitesoft/whatsapp_scratch.
Note property a and d from those json. When I write this answer, the values are>> a: 5eItLCbGXx3CKpybxo81/A== and d: 2.19.15
_MD5_CLASSES = "5eItLCbGXx3CKpybxo81/A=="
_VERSION = "2.19.15"
Recently I've updated my composer to 1.0.3. After that I'm getting following error. "PHP Fatal error: Cannot redeclare class Error"
Here is my sample code.
<?php
require "./vendor/autoload.php";
require "MyErrorLog.php"; // Class file having class name as "Error"
Previously, I was using some code without having any problem. But, after updating composer & it's dependance I'm getting this error.
Shall I need to use a namespace to resolve this or something else I need to do?
If I use following the piece of code.
require "./vendor/autoload.php";
$Error = new Error();
echo '<pre>';
print_r($Error);
echo '</pre>';
I'm getting this out put.
Error Object
(
[message:protected] =>
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/testing/composer-test1/composer-test.php
[line:protected] => 7
[trace:Exception:private] => Array
(
)
[previous:Exception:private] =>
)
Anyone, help me to understand what's exactly it is & what it's uses?
Adding my composer.json file content
{
"require": {
"defuse/php-encryption": "^2.0"
}
}
My problem is quite strange (at least to me) as I have a request URL that works in the console but throws the Sorry, that page does not exist error in my php script, even though the connection is up and running.
So this
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_secret']);
$user = $connection->get('account/verify_credentials');
print_r($user);
works great, the $user data is printed out on the screen.
However, I am unable to check a friendship status as:
$x = $connection->get('https://api.twitter.com/1.1/friendships/show.json?source_id=707482092&target_id=755811768&target_screen_name=assetspersonifi');
As I get the error.
When I put this request into the Twitter API console, it gives back the json that I don't receive in my php code.
I'm using Abraham's twitteroauth library but this does not work either:
$follows_faelazo = $connection->get('friendships/exists', array('user_a' => 'blfarago', 'user_b' => 'faelazo'));
if(!$follows_faelazo){
echo 'You are NOT following #faelazo!';
$connection->post('friendships/create', array('screen_name' => 'faelazo'));
} else {
print_r($follows_faelazo);
}
stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [message] => Sorry, that page does not exist [code] => 34 ) ) )
I read that friendships/exists API is no longer supported by the Twitter API and I should use friendships/show but how if it's not working as you see above?
To prove that everything else is working, I can follow others with
$connection->post('friendships/create', array('screen_name' => 'faelazo'));
Why?
I found a way. Here's the documentation
$following = $connection->get('friendships/show', array(
'source_screen_name' => $_SESSION['username'],
'target_screen_name' => $screen_name_to_follow,
));
An alternative would be
$following = $connection->get('friendships/lookup', array('screen_name' => $screen_name_to_follow));
Look it up in Twitter doc.
Related to this question: How to request an answer from a SOAP XML API?
I have this PHP script sending the request with the required fields:
$client = new SoapClient('https://live.domainbox.net/?WSDL');
$params = array(
'AuthenticationParameters' => array(
'Reseller' => 'resellername',
'Username' => 'myusername',
'Password' => 'mypassword'
),
'CommandParameters' => array(
'DomainName' => 'mydomain.com',
'LaunchPhase' => 'GA'
)
);
$result = $client->CheckDomainAvailability($params);
print_r($result);
I get the following error message:
Fatal error: Uncaught SoapFault exception: [soap:VersionMismatch]
Possible SOAP version mismatch: Envelope namespace
http://schemas.xmlsoap.org/soap/envelope/ was unexpected.
Expecting http://www.w3.org/2003/05/soap-envelope. in
/home/nosa/public_html/dev/check-domain-availability.php:20 Stack
trace: #0
/home/nosa/public_html/dev/check-domain-availability.php(20):
SoapClient->__call('CheckDomainAvai...', Array) #1
/home/nosa/public_html/dev/check-domain-availability.php(20):
SoapClient->CheckDomainAvailability(Array) #2 {main} thrown in
/home/nosa/public_html/dev/check-domain-availability.php on line 20
I removed and recompiled apache to include the latest SOAP version available using WHM/cPanel.
My question is:
How do I send the correct envelope namespace?
When building your soap_client object, you can pass an option's array, by default, the version will be 1.1 as per php documentation.
The error you have seems to point out that the service might be SOAP 1.2 so you need to set it to 1.2...
$client = new SoapClient('https://live.domainbox.net/?WSDL', array('soap_version' => SOAP_1_2));
Try that out!
I'm trying to connect to a dll that was supplied to me, I don't have the ability to edit it.
Is the "Invalid syntax" error refering to a method within the dll or something with the php code?
try {
$testConnection = new COM("SomebodySpecial.DLL");
} catch (com_exception $e) {
echo "";
print_r( array( 'errorCode' => $e->getCode(),
'errorMessage' => $e->getMessage(),
'errorFile' => $e->getFile(),
'errorLine' => $e->getLine()));
echo "";
}
[errorCode] => -2147221020
[errorMessage] => Failed to create COM object `SomebodySpecial.DLL': Invalid syntax
[errorFile] => D:\Inetpub\wwwroot-dev\test.php
[errorLine] => 9
As the error message indicates, you provided an invalid parameter to the COM constructor.
The parameter is a COM ID, not a DLL filename.