I'm using EHttpClient extension yii.
My Code:
$file = file_get_contents($path, true);
Yii::import('ext.EHttpClient.*');
$client = new EHttpClient('https://secure.efaxdeveloper.com/EFax_WebFax.serv', array(
'maxredirects' => 3,
'timeout' => 30,
'Content-Type' => 'application/x-www-form-urlencoded',
'adapter' => 'EHttpClientAdapterCurl'));
$client->setParameterPost(array('id'=>urlencode("2313125942"), 'xml'=>urlencode($file)));
SiteHelper::printShow($client);
$response = $client->request("POST");
var_dump($response->isSuccessful());
SiteHelper::printShow($response);
My xml data:
<?xml version="1.0"?>
<OutboundRequest>
<AccessControl>
<UserName>b23s2323</UserName>
<Password>b23s2323</Password>
</AccessControl>
<Transmission>
<TransmissionControl>
<Resolution>STANDARD</Resolution>
</TransmissionControl>
<DispositionControl>
<DispositionLevel>BOTH</DispositionLevel>
<DispositionEmails>
<DispositionEmail>
<DispositionAddress>johnmorris201615#gmail.com</DispositionAddress>
</DispositionEmail>
</DispositionEmails>
</DispositionControl>
<Recipients>
<Recipient>
<RecipientFax>8189790412</RecipientFax>
</Recipient>
</Recipients>
<Files>
<File>
<FileContents>Base64 pdf here</FileContents>
<FileType>pdf</FileType>
</File>
</Files>
</Transmission>
</OutboundRequest>
The information of my request:
EHttpClient Object
(
[config:protected] => Array
(
[maxredirects] => 3
[strictredirects] =>
[useragent] => EHttpClient
[timeout] => 30
[adapter] => EHttpClientAdapterCurl
[httpversion] => 1.1
[keepalive] =>
[storeresponse] => 1
[strict] => 1
[output_stream] =>
[encodecookies] => 1
[rfc3986_strict] =>
[content-type] => application/x-www-form-urlencoded
)
[adapter:protected] =>
[uri:protected] => EUriHttp Object
(
[_username:protected] =>
[_password:protected] =>
[_host:protected] => secure.efaxdeveloper.com
[_port:protected] => 443
[_path:protected] => /EFax_WebFax.serv
[_query:protected] =>
[_fragment:protected] =>
[_regex:protected] => Array
(
[alphanum] => [^\W_]
[escaped] => (?:%[\da-fA-F]{2})
[mark] => [-_.!~*'()\[\]]
[reserved] => [;\/?:#&=+$,]
[unreserved] => (?:[^\W_]|[-_.!~*'()\[\]])
[segment] => (?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:#&=+$,;])*)
[path] => (?:\/(?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:#&=+$,;])*)?)+
[uric] => (?:[;\/?:#&=+$,]|(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2}))
)
[_scheme:protected] => https
)
[headers:protected] => Array
(
)
[method:protected] => GET
[paramsGet:protected] => Array
(
)
[paramsPost:protected] => Array
(
[id] => 2313125942
[xml] => The%encoded%url%xml%data
)
[cookiejar:protected] =>
[last_request:protected] =>
[last_response:protected] =>
[redirectCounter:protected] => 0
[_unmaskStatus:protected] =>
[_queryBracketsEscaped:protected] => 1
)
I already read the documentation from https://secure.efaxdeveloper.com/downloads.jsp Outbound already set all the required fields on xml data and request post. But I always get this error from efax developer API:
Post Unsuccessful!
Your request has failed due to invalid data.
Please refer to our documentation prior to resubmitting.
Error Level: User
Error Message: XML data argument was not passed.
Please contact us at 888-278-8666 if you continue to encounter errors.
Error Message : XML data argument was not passed What is wrong with my xml data?
(*Note on my request the xml post parameter is set the encoded file contents of my xml).
I used PHP efax instead.
PHP eFax is a PHP class that wraps the eFax® Developer API. Use PHP
eFax to automate the task of sending and receiving faxes
electronically from your PHP-powered web server.
Don't use urlencode. Just set the content type to application/x-www-form-urlencoded.
Related
EDIT: See solution. Problem was in how the Twitter library was instantiated.
I'm trying to get Twitter authorization using OAuth2. I'm able to get it to work in a simple test script, but when I try to use it in my WordPress plugin it doesn't work.
I'm using The PHP League's OAuth2 Client with a library I wrote to connect it to Twitter; the test script is in the README.
The test script stores the OAuth2 state in $_SESSION; the actual app stores it in a WordPress transient. I've confirmed the integrity of the data through the pipeline:
Data from Twitter library after generating auth URL:
Array
(
[url] => https://twitter.com/i/oauth2/authorize?redirect_uri=https%3A%2F%2Fsmol.blog%2Fwp-json%2Fsmolblog%2Fv2%2Fconnect%2Fcallback%2Ftwitter&code_challenge=EV7BCVYmkvCnIlVLH6cVzrvjNloQlleAkkYwLLgg41w&code_challenge_method=S256&state=fd5824ef415aa325f1f68d3504bb16b3&scope=tweet.read%20users.read%20offline.access&response_type=code&approval_prompt=auto&client_id=MjVXMnRGVUN5Ym5lcVllcTVKZkk6MTpjaQ
[state] => fd5824ef415aa325f1f68d3504bb16b3
[verifier] => u7Zbf1gVEFZLyTgr_2Hk~i5P2pt8VgicyhZgdeO0pAyIZqhSoYqglHaIxsNRjHz0AHpwhlU1~Q
)
Data pulled from WordPress transient during the callback (stored slightly differently):
Array
(
[id] => fd5824ef415aa325f1f68d3504bb16b3
[userId] => 1
[info] => Array
(
[verifier] => u7Zbf1gVEFZLyTgr_2Hk~i5P2pt8VgicyhZgdeO0pAyIZqhSoYqglHaIxsNRjHz0AHpwhlU1~Q
)
)
Request object to Twitter's token endpoint:
GuzzleHttp\\Psr7\\Request Object
(
[method:GuzzleHttp\\Psr7\\Request:private] => POST
[requestTarget:GuzzleHttp\\Psr7\\Request:private] =>
[uri:GuzzleHttp\\Psr7\\Request:private] => GuzzleHttp\\Psr7\\Uri Object
(
[scheme:GuzzleHttp\\Psr7\\Uri:private] => https
[userInfo:GuzzleHttp\\Psr7\\Uri:private] =>
[host:GuzzleHttp\\Psr7\\Uri:private] => api.twitter.com
[port:GuzzleHttp\\Psr7\\Uri:private] =>
[path:GuzzleHttp\\Psr7\\Uri:private] => /2/oauth2/token
[query:GuzzleHttp\\Psr7\\Uri:private] =>
[fragment:GuzzleHttp\\Psr7\\Uri:private] =>
[composedComponents:GuzzleHttp\\Psr7\\Uri:private] =>
)
[headers:GuzzleHttp\\Psr7\\Request:private] => Array
(
[Host] => Array
(
[0] => api.twitter.com
)
[content-type] => Array
(
[0] => application/x-www-form-urlencoded
)
[Authorization] => Array
(
[0] => Basic [base64-encoded app id and secret redacted]
)
)
[headerNames:GuzzleHttp\\Psr7\\Request:private] => Array
(
[content-type] => content-type
[host] => Host
[authorization] => Authorization
)
[protocol:GuzzleHttp\\Psr7\\Request:private] => 1.1
[stream:GuzzleHttp\\Psr7\\Request:private] => GuzzleHttp\\Psr7\\Stream Object
(
[stream:GuzzleHttp\\Psr7\\Stream:private] => Resource id #101
[size:GuzzleHttp\\Psr7\\Stream:private] =>
[seekable:GuzzleHttp\\Psr7\\Stream:private] => 1
[readable:GuzzleHttp\\Psr7\\Stream:private] => 1
[writable:GuzzleHttp\\Psr7\\Stream:private] => 1
[uri:GuzzleHttp\\Psr7\\Stream:private] => php://temp
[customMetadata:GuzzleHttp\\Psr7\\Stream:private] => Array
(
)
)
)
Body of said request:
client_id=MjVXMnRGVUN5Ym5lcVllcTVKZkk6MTpjaQ&client_secret=[redacted]&grant_type=authorization_code&code=aTVUMDkybzdsVmExOEQ5MjdrVjVOQVZ3YTVDbUdmTXRDMktZSzBaSGFqVk5LOjE2NjUzNjc1MjIyNjg6MToxOmFjOjE&code_verifier=u7Zbf1gVEFZLyTgr_2Hk~i5P2pt8VgicyhZgdeO0pAyIZqhSoYqglHaIxsNRjHz0AHpwhlU1~Q
The error:
PHP Fatal error: Uncaught League\\OAuth2\\Client\\Provider\\Exception\\IdentityProviderException: Value passed for the token was invalid. in /var/www/html/wp-content/plugins/smolblog-wp/vendor/smolblog/oauth2-twitter/src/Twitter.php:169
I know I'm missing something stupid here. But I can't for the life of me figure out what. There's a lot more code in the actual app than there is in the test script, but I've verified the data at multiple points in the stack, including right before it's sent to Twitter. What else do I need to be testing, or is there something that I'm forgetting?
Found the error. In the test script, the redirectUri was passed into the constructor of the OAuth2 client; In the app, it was passed into the getAuthorizationUrl function. This worked for the initial call to Twitter, but (apparently) that data is also needed for the getAccessToken call. So here's the fix.
Old and busted:
new Twitter([
'clientId' => $app->env->twitterAppId ?? '',
'clientSecret' => $app->env->twitterAppSecret ?? '',
])
New hotness:
new Twitter([
'clientId' => $app->env->twitterAppId ?? '',
'clientSecret' => $app->env->twitterAppSecret ?? '',
'redirectUri' => "{$app->env->apiBase}connect/callback/twitter",
])
I'm trying to integrate the MailChimp API 3.0 with PHP into a custom built CMS. When I try to create a single campaign with the following code I have an error message.
CODE:
$apikey = <--api-key-->;
$list_id = <--list-id-->;
use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp($apikey);
$result = $MailChimp->post("campaigns", [
'type' => 'regular',
'recipients' => ['list_id' => '$list_id'],
'settings' => ['subject_line' => 'test subject',
'reply_to' => 'test#test.com',
'from_name' => 'test name'],
]);
echo "<pre>";
print_r($result);
print_r($MailChimp->getLastRequest());
echo "</pre>";
ERROR MESSAGE:
Array
(
[type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
[title] => Invalid Resource
[status] => 400
[detail] => The resource submitted could not be validated. For field-specific details, see the 'errors' array.
[instance] =>
[errors] => Array
(
[0] => Array
(
[field] =>
[message] => Schema describes object, NULL found instead
)
)
)
USING print_r($MailChimp->getLastRequest());
Array
(
[method] => post
[path] => campaigns
[url] => https://us8.api.mailchimp.com/3.0/campaigns
[body] =>
[timeout] => 10
[headers] => POST /3.0/campaigns HTTP/1.0
User-Agent: DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)
Host: us8.api.mailchimp.com
Accept-Encoding: deflate, gzip
Accept: application/vnd.api+json
Content-Type: application/vnd.api+json
Authorization: apikey <--api-key-->
Content-Length: 0
)
I have checked the documentation, searched through SO, but haven't found anything. If anyone has a working code that creates a simple campaign I can start working with, I would appreciate it. What am I missing?
This is the code I used to get it done, also check for the encoding, it can cause problems
$result = $MailChimp->post("campaigns", [
"type" =>"regular",
"recipients"=> [
"list_id"=> "$list_id"
]
,
"settings"=> [
"subject_line"=> "test subject",
"from_name"=> "test name",
"reply_to"=> "test#test.com"
]
]);
I am doing the login using twitter oauth functionality. I am getting the following object from $client = $token->getHttpClient($config) method:
Zend_Oauth_Client Object
(
[_config:protected] => Zend_Oauth_Config Object
(
[_signatureMethod:protected] => HMAC-SHA1
[_requestScheme:protected] => header
[_requestMethod:protected] => POST
[_version:protected] => 1.0
[_callbackUrl:protected] => http://roomstayssvn.com/register/twittercallback
[_siteUrl:protected] => http://twitter.com/oauth
[_requestTokenUrl:protected] =>
[_accessTokenUrl:protected] =>
[_authorizeUrl:protected] =>
[_consumerKey:protected] => b04fuaxLR2d035FN8tTkQ
[_consumerSecret:protected] => NGPPovdXDnSpivNoMNIgA609ZJIB8GVKGgs6yEF8A
[_rsaPrivateKey:protected] =>
[_rsaPublicKey:protected] =>
[_token:protected] => Zend_Oauth_Token_Access Object
(
[_params:protected] => Array
(
[oauth_token] => 299516752-tksjJZUR7Q2gwrDRDpLOLCrYhySTGWz1SBwTKcRU
[oauth_token_secret] => 7S9R2FLuB0GT4vvy0GerThUnpkbSTeSalURib48Sx20
[user_id] => 299516752
[screen_name] => jogkunal5
)
)
.....
..... and so on
I want to print user_id and screen_name. How can I print it?
Following should work
$user_id = $client->getToken()->getParam('user_id');
$screen_name = $client->getToken()->getParam('screen_name');
Zend_Oauth_Client::__call() proxies any method of Zend_Oauth_Config.
Zend_Oauth_Config::getToken() returns Zend_Oauth_Token
Zend_Oauth_Token::getParam() gets the value for a parameter
Read the docs from here.
Its better you use a Good IDE that supports Zend framework.
Using Zend amazon service, I have fetched till there.
$url=$result->LargeImage->Url;
print_r($url);
the output of this is:
Zend_Uri_Http Object
(
[_username:protected] =>
[_password:protected] =>
[_host:protected] => ecx.images-amazon.com
[_port:protected] =>
[_path:protected] => /images/I/41voDxJS62L.jpg
[_query:protected] =>
[_fragment:protected] =>
[_regex:protected] => Array
(
[escaped] => %[[:xdigit:]]{2}
[unreserved] => [A-Za-z0-9-_.!~*'()\[\]]
[segment] => (?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*'()\[\]:#&=+$,;])*
[path] => (?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*'()\[\]:#&=+$,;])*)?)+
[uric] => (?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*'()\[\];\/?:#&=+$,])
)
[_scheme:protected] => http
)
We can't do echo $url->_host:protected here as 'protected' is keyword.
How do I access that?
Can anyone help please?
Thanks
Use the getter.
$result->LargeImage->Url->getHost()
or
$url->getHost()
See the documentation : http://framework.zend.com/apidoc/1.9/Zend_Uri/Zend_Uri_Http.html
I'm not really familiar working with soap.
I wanted to pull data from soap server, but it seems there are problem (Object reference not set to an instance of an object.).
Here the debug code from my code:
stdClass Object ( [GetSalesBannersResult] => stdClass Object ( [Result] => [Message] => Object reference not set to an instance of an object. [List] => stdClass Object ( ) ) )
Request :<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.ozsale.com.au/API/V2"><SOAP-ENV:Body><ns1:GetSalesBanners><ns1:saleCategoryID>40F80218-A9E1-43C4-96FF-4C046D192A21</ns1:saleCategoryID><ns1:getTopThree>true</ns1:getTopThree></ns1:GetSalesBanners></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetSalesBannersResponse xmlns="http://ws.ozsale.com.au/API/V2"><GetSalesBannersResult><Result>false</Result><Message>Object reference not set to an instance of an object.</Message><List /></GetSalesBannersResult></GetSalesBannersResponse></soap:Body></soap:Envelope>
and it is my code so far:
<?php
// create a connection to the local host mono .NET pull back the wsdl to get the functions names
// and also the parameters and return values
$client = new SoapClient("http://www.ozsale.com.au/api/v2/api.asmx?WSDL",
array(
"trace" => 1, // enable trace to view what is happening
"exceptions" => 0, // disable exceptions
"cache_wsdl" => 0)
);
// get a response from the WSDL zend server function getQuote for the day monday
print_r($client->GetSalesBanners(array(
"saleCategoryID" => "40F80218-A9E1-43C4-96FF-4C046D192A21",
"getTopThree" =>"1"
))
);
//print_r($client);
// display what was sent to the server (the request)
echo "<p>Request :".htmlspecialchars($client->__getLastRequest()) ."</p>";
// display the response from the server
echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>";
?>
and then the api documentation for is here http://www.ozsale.com.au/api/v2/api.asmx?op=GetSalesBanners
Anyone could help figure out whether what is wrong here...
New update of my question. now the document api is here http://www.ozsale.com.au/api/v2/api.asmx?op=GetPublicSalesBanners
I attempt to pull data with these following info:
'saleCategoryID' => '40F80218-A9E1-43C4-96FF-4C046D192A21',
'countryID'=> 'AS',
'languageID'=> 'EN',
'getTopThree' =>'1'
My code is here:
<?php
// create a connection to the local host mono .NET pull back the wsdl to get the functions names
// and also the parameters and return values
$client = new SoapClient("http://www.ozsale.com.au/api/v2/api.asmx?WSDL",
array(
"trace" => 1, // enable trace to view what is happening
"exceptions" => 0, // disable exceptions
"cache_wsdl" => 0)
);
// get a response from the WSDL zend server function getQuote for the day monday
print_r($client->GetPublicSalesBanners(array(
'saleCategoryID' => '40F80218-A9E1-43C4-96FF-4C046D192A21',
'countryID'=> 'AS',
'languageID'=> 'EN',
'getTopThree' =>'1'
))
);
// display what was sent to the server (the request)
echo "<p>Request :".htmlspecialchars($client->__getLastRequest()) ."</p>";
// display the response from the server
echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>";
?>
And when I trying to see how it work, it's output like this:
SoapFault Object ( [message:protected] => Server was unable to process request. ---> There was an error generating the XML document. ---> <>f__AnonymousType2a`2[System.String,System.Object[]] cannot be serialized because it does not have a parameterless constructor. [string:Exception:private] => [code:protected] => 0 [file:protected] => /Users/resarahman/Documents/xampp/htdocs/testing/soap/test.php [line:protected] => 17 [trace:Exception:private] => Array ( [0] => Array ( [file] => /Users/resarahman/Documents/xampp/htdocs/testing/soap/test.php [line] => 17 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => GetPublicSalesBanners [1] => Array ( [0] => Array ( [saleCategoryID] => 40F80218-A9E1-43C4-96FF-4C046D192A21 [countryID] => AS [languageID] => EN [getTopThree] => 1 ) ) ) ) [1] => Array ( [file] => /Users/resarahman/Documents/xampp/htdocs/testing/soap/test.php [line] => 17 [function] => GetPublicSalesBanners [class] => SoapClient [type] => -> [args] => Array ( [0] => Array ( [saleCategoryID] => 40F80218-A9E1-43C4-96FF-4C046D192A21 [countryID] => AS [languageID] => EN [getTopThree] => 1 ) ) ) ) [previous:Exception:private] => [faultstring] => Server was unable to process request. ---> There was an error generating the XML document. ---> <>f__AnonymousType2a`2[System.String,System.Object[]] cannot be serialized because it does not have a parameterless constructor. [faultcode] => soap:Server [detail] => )
Request :<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.ozsale.com.au/API/V2"><SOAP-ENV:Body><ns1:GetPublicSalesBanners><ns1:saleCategoryID>40F80218-A9E1-43C4-96FF-4C046D192A21</ns1:saleCategoryID><ns1:countryID>AS</ns1:countryID><ns1:languageID>EN</ns1:languageID><ns1:getTopThree>true</ns1:getTopThree></ns1:GetPublicSalesBanners></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Server was unable to process request. ---> There was an error generating the XML document. ---> <>f__AnonymousType2a`2[System.String,System.Object[]] cannot be serialized because it does not have a parameterless constructor.</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
Any idea why and what is wrong here ?
Your inputs look OK, unless there are any special requirements such as a SOAP header. That's most likely a problem with the web service that the provider needs to fix, rather than a problem with your client code. I suggest contacting them.