I have the following PHP code, which up to a week or so ago was working to send Twitter direct messages to a particular user. I now get "HTTP_OAuth_Exception: Unable to connect to tcp://api.twitter.com:80. Error #0: php_network_getaddresses: getaddrinfo failed: Name of service not known in /usr/share/pear/HTTP/OAuth/Consumer.php on line 257"
I've searched around and can't find that anything has changed with Twitter since it was working and the server configuration also hasn't changed. I tried using SSL in case Twitter suddenly required connection via SSL, but that gave basically the same error (except it said ssl and port 443).
I'm at a loss to see what's wrong and don't believe anything changed on my side. My code is based on the example in the Services_Twitter documentation (http://pear.php.net/package/Services_Twitter/docs/latest/Services_Twitter/Services_Twitter.html#var$oauth)
Any help would be greatly appreciated.
require_once 'Services/Twitter.php';
require_once 'HTTP/OAuth/Consumer.php';
$twitterto = 'xxxxxxxxxxxx';
$message='This is a test message';
$cons_key='xxxxxxxxxxxx';
$cons_sec='xxxxxxxxxxxx';
$auth_tok='xxxxxxxxxxxx';
$tok_sec='xxxxxxxxxxxx';
try {
$twitter = new Services_Twitter();
$oauth = new HTTP_OAuth_Consumer($cons_key,
$cons_sec,
$auth_tok,
$tok_sec);
$twitter->setOAuth($oauth);
// The error is raised on the following line.
$twitter->direct_messages->new($twitterto, $message);
$twitter->account->end_session();
} catch (Services_Twitter_Exception $e) {
echo $e->getMessage();
}
Related
Trying to upload a csv from a remote URL to azure storage using the PHP SDK. I seem to keep getting this error. I have tried it without the SDK using curl and i still get the same error.
`PUT resulted in a `403 Server failed to authenticate the request.
Make sure the value of Authorization header is formed correctly including the signature.` response:
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate (truncated...)
in C:\wamp64\www\azurescript\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113
Here is my PHP code which i am using:
<?php
require_once 'vendor/autoload.php';
use MicrosoftAzure\Storage\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Common\ServiceException;
use MicrosoftAzure\Blob\Models\SetBlobPropertiesOptions;
$key = base64_encode("abc");
$connectionString = "DefaultEndpointsProtocol=https;AccountName=username;AccountKey={$key}";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
// Grab the csv from the remote url
$csv = fopen("http://www.xxxxx.com/wp-cron.phpexport_hash=yyyyyy&export_id=1&action=get_data", "r");
$blobName = "test";
try {
// Upload the blob
$blobRestProxy->createBlockBlob("container", $blobName, $csv);
}
catch(ServiceException $e){
// Errors
$code = $e->getCode();
$errorMessage = $e->getMessage();
}
Cant seem to this. Some guidance would be nice
The error is related to 403 auth failed. Please maker sure:
Your account name and account key is valid and not expired. You can confirm this by trying loging with Azure Storage Explorer, or check on your Azure Portal.
You do not need base64_encode($key) again after receiving your key from Azure Storage. The key received from Azure Storage is already base64_encoded.
The auth issue is related to your key not being properly set up. Not sure why you decided to encode it, but... you need to use the storage access key exactly as it's presented to you.
In fact, the entire connection string is constructed for you already; no need to build it yourself.
I have installed today Azure Client Libraries using direction on this page https://learn.microsoft.com/en-us/azure/storage/blobs/storage-php-how-to-use-blobs#create-a-php-application
but i am getting below error.
400: Fail:
Code: 400
Value: The value for one of the HTTP headers is not in the correct format.
details (if any): InvalidHeaderValueThe value for one of the HTTP headers is not in the correct format. RequestId:f0046f48-001e-0046-22ab-2823fb000000 Time:2017-09-08T14:06:55.1682373Zx-ms-version2012-02-12.
My Code is as below:
require_once 'vendor/autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions;
use MicrosoftAzure\Storage\Blob\Models\PublicAccessType;
use MicrosoftAzure\Storage\Common\ServiceException;
$connectionString = "DefaultEndpointsProtocol=http;AccountName=MyAccountName;AccountKey=4cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
//create container
$createContainerOptions = new CreateContainerOptions();
// private to the account owner.
$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
// Set container metadata.
$createContainerOptions->addMetaData("category", "my first category data");
try {
// Create container.
$blobRestProxy->createContainer("test", $createContainerOptions);
}
catch(ServiceException $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here:
// http://msdn.microsoft.com/library/azure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo "Erro in create container <br><br>";
echo $code.": ".$error_message."<br />";
//print_r($e);
}
in above code i got "Class not found" error so updated code as below:
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Common\ServiceException;
after above change in code, "class not found" error solved and also i checked that connection string is working well but getting error, which described in start of my question.
Thanks :)
Your code looks fine. I can reproduce the error with version v.0.4.2 of Azure SDK for PHP. I got problem solved by upgrading the SDK to the latest version (v0.5.5)
{
"require": {
"microsoft/windowsazure": "^0.5.5"
}
}
There is Azure SDK Version problem so you can download SDK v0.5.5 from my this blog and also can work on your PHP 5.4
http://mytechdevelopment.blogspot.com/2018/01/azure-sdk-055-for-php-54-or-igher.html
Environment: Linux
Backend: Drupal/PHP.
Sharepoint API in use: https://github.com/thybag/PHP-SharePoint-Lists-API/
I have successfully established a connection with sharepoint using WSDL file. I am able to insert, delete and update the lists using the above API. But I am not able to add a attachment to the list item. I tried using the API function (addAttachment), but it is throwing the following error-
"Caught exception: Error (soap:Server) Exception of type
'Microsoft.SharePoint.SoapServer.SoapServerException' was
thrown.,more=Detailed: The security validation for this page is
invalid. Click Back in your Web browser, refresh the page, and try
your operation again."
Please let me know if anybody facing the same issue.
Thanks.
I got the solution for the above problem. The issue lies in this file
PHPSharePointListsAPI/src/Thybag/Auth/SharePointOnlineAuth.php on line 22
Just replace line 22 with the below code :-
$headers = array('SOAPAction: "' . $action . '"');
Hope that helps if anyone's stuck with it since ages.. :P
I am trying to connect to a pop3 email account that is hosted by my website host. My website is a shared host. The email host that I check my emails with windows live is mail.mysite.com with port 110 and it works fine.
Using php and imap I have not had any luck. I did check and my host does have IMAP installed. After that I fought with it for a few hours and learned when imap_open fails it tries 3 more times just for fun. As I started with imap_last_error() as my error checker it was telling me Cannot connect to Mail: Too many login failures Once I figured out what was happening it did not take long to figure out how to get the rest of the errors and then how to turn it off so it does not retry.
Now I am getting syntax error I have tried dozens and dozens different variations of hostname. Below I include 4 so people can see some of the saner things I have tried and the results.
As I am completely new to this I am likely missing something obvious to someone with more experience. I am also open to other ways to go about this. I just want to be able to use a php script to open and read Emails on a particular account. I am not picky about which or what kind of interface. I have been trying IMAP as it is the only one that I have found.
//$hostname = '{mail.mysite.com:110}INBOX'; //array(1) { [0]=> string(49) "[CLOSED] IMAP connection broken (server response)" }
//$hostname = '{mail.mysite.com:110/pop3}INBOX'; //array(1) { [0]=> string(142) "Certificate failure for mail.mysite.com: Server name does not match certificate: /OU=Domain Control Validated/CN=*.websitesource.net" }
$hostname = "{mail.mysite.com:110/pop3/novalidate-cert}INBOX"; //array(1) { [0]=> string(12) "syntax error" }
//$hostname = '{mail.websitesource.net:110/pop3}INBOX'; //array(1) { [0]=> string(12) "syntax error" }
//A temp account for testing
$user = 'a#mysite.com';
$password = '12345678!';
/* try to connect */
$inbox = imap_open($hostname,$username,$password,0,0) or die( var_dump(imap_errors ()) );
//see errors at top of code, current error 'syntax error'
You are using the wrong variable. Replace $username with $user
$inbox = imap_open($hostname,$user,$password,0,0) or die( var_dump(imap_errors ()) );
Ok I feel rather silly. $username is not the same as $user. When I started with various scripts I did not know about the Certificate problem(different hosts) and somewhere along the lines I no doubt copied part of one test script and part of another and wolla a simple bug that was hidden by the earlier bugs.
I make use of a great class made by Jaisen: http://github.com/jmathai/twitter-async/tree/master. Recently twitter has been up and down and I am sure it will continue to be the same in the future so I am trying to cut down on my dependency on twitter being actually working.
The following is what I have in my header.php and it is right at the top and it generates the login URL for each user. If twitter is down, my site hangs for as long as it needs to and it throws an exception. So I have to catch these expceptions which I have sort of done.
I now want to just cancel the request to the API after a few seconds and just load the page and keep trying behind the scenes. How can I best do this?
<?php include './twitter/EpiCurl.php'; include './twitter/EpiOAuth.php'; include './twitter/EpiTwitter.php';
$consumer_key = 'mykey';
$consumer_secret = 'mysecret';
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
try{
$twiturl = $twitterObj->getAuthenticateUrl();
$url = "window.open('".$twiturl."','Login', 'left=20,top=20,width=500,height=500,toolbar=0,resizable=1'); startLoad();";
}catch(EpiOAuthBadRequestException $e){
// bad request exception do something
$statusMessage = 'Oops an error has occurred: ' . $e->getMessage();
}catch(EpiOAuthUnauthorizedException $e){
// bad authorization..probably bad tokens, do something different
$statusMessage = 'Oops an error has occurred: ' . $e->getMessage();
}catch(EpiOAuthException $e){
// uh oh, unknown oauth exception
$statusMessage = 'Oops, an unknown authorisation error has occurred! The mojo team have been notified! Please try again.';
}
if(isset($statusMessage)){
}
?>
Any improvement of the above code will also be appreciated.
Thanks all
The library supports a value to be passed into the curl timeout.
$twitterObj->setTimeout($secs_request_timeout);
I just added support for passing in a connection timeout as well. Unable to run unit tests because I'm being rate limited. Will commit this once I can verify that it works.
$twitterObj->setTimeout($secs_request_timeout, $secs_connection_timeout);
Use curl_setopt(CURLOPT_CONNECTTIMEOUT, 1 /* 1 second timeout */); to cause CURL to give up if a connection isn't established in 1 second. I use this when connecting to the facebook API, 'cause they've been pretty unreliable in the past as well.