having an issue with the Twitter API. Using tmhOAuth. Constantly getting the following 404 error:
"Sorry, that page does not exist :34"
I can 1/account/verify_credentials and 1/statuses/update perfectly fine but oauth/request_token returns the 404. The Callback URL in my app settings is set to https://google.com/ for testing purposes.
require_once('tmhOAuth/tmhOAuth.php');
$connection = new tmhOAuth(array(
'consumer_key' => '******',
'consumer_secret' => '******',
'user_token' => '******',
'user_secret' => '******'
));
$connection->request('POST',
$connection->url('oauth/request_token'),
array('oauth_callback' => 'oob')
);
return $connection->response['code'];
Any help is greatly appreciated, drawing a blank.
I know this is an old one, but for anyone else looking, you need to add an extra empty string parameter to url(), like so..
$connection->request('POST',
$connection->url('oauth/request_token', ''),
array('oauth_callback' => 'oob')
);
Related
Basically, I am trying to connect to a SOAP service with 2 way SSL (HTTP client certificate authentication).
I am using PHP SoapClient for this within Laravel.
This is what I have, and it allows me to connect and returns the expected response. So the method is basically correct and the certificate is fine etc. It's just I am having trouble with what I guess is the 2 way SSL part.
$client = new \SoapClient('localwsdlfile.wsdl', array(
'local_cert' => 'localcert.pem',
'passphrase' => 'passphrase',
// 'location' => 'https://wsmurl/login/' // Uncomment to login
));
$response = $client->Get(array(
"AccessKey" => "accesskey",
"ProductID" => "SOMEPRODUCT",
"Scope" => "SOMESCOPE",
"Parameters" => array('Param' => array('_' => 'DATATOLOOKUP', 'id'=>'MOREDATATOLOOKUP'))
));
print_r($response);
The only problem is (obviously because I'm doing something wrong), is I need to add the line 'location' => 'https://wsmurl/login/' the first time I try to connect, otherwise I get an error "SoapFault Login Required"
I then remove the line 'location' => 'https://wsmurl/login/', otherwise, I get an error "SoapFault looks like we got no XML document".
The service provider has a 600 second timeout, where I don't have to "login" again for upto 600 seconds.
After removing this line 'location' => 'https://wsmurl/login/', then it works as expected. Obviously, I can't manually add and remove this line, and I guess I am not doing this correctly.
Can someone tell me a better way to do this please?
Thanks,
Because the location for the login and localwsdlfile.wsdl is different, I could not do it with one call. So we created a function using curl to login and if login is successful it will proceed to the soapclient. Thanks to Brian from freelancer for his assistance here.
$client = new SoapClient('wsdl/VocusSchemas/localwsdlfile.wsdl', array(
'trace' => 1,
'exception' => true
));
try {
$response = $client->Get(array(
// "AccessKey" => "MADAITABNSAATOT1",
"AccessKey" => "accesskey",
"ProductID" => "SOMEPRODUCT",
"Scope" => "SOMESCOPE",
"Parameters" => array('Param' => array('_' => 'DATATOLOOKUP', 'id' => 'MOREDATATOLOOKUP'))
));
I have been trying to make an API to retweet using status id, but I got a 410 status error. I searched how to make a retweet and I found the following code, but I face the mentioned error:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require 'tmhOAuth.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => $consumerKey,
'consumer_secret' => $consumerSecret,
'user_token' => $oAuthToken,
'user_secret' => $oAuthSecret,
'curl_timeout' => 60,
'curl_ssl_verifypeer' => 0
));
$code = $tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/retweet/'),
array('id' => '505041593686974464' ));
echo $code;
?>
How can I retweet in Twitter using the tmhOAuth.php class?
Note: I already created an app to post text and images to my Twitter using the tmhOAuth.php class.
From dev.twitter.com:
This resource is gone. Used to indicate that an API endpoint has been
turned off. For example: “The Twitter REST API v1 will soon stop
functioning. Please migrate to API v1.1.”
I am using tmhoauth library to build a small twitter app demo. Everything works fine like retrieving tweets, making searches etc. But when I try to retrieve trending topics using woeid, I get a 404 - This page does not exist error. I have tried different woeids'.
I will be grateful if someone could point what I am doing wrong.
here is my code.
public function trends1(){
require 'tmhOAuth.php';
require 'tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => $this->consumerkey,
'consumer_secret' => $this->consumersecret,
'user_token' => $this->accesstoken,
'user_secret' => $this->accesstokensecret,
'curl_ssl_verifypeer' => false
));
$args = array('id' => '23424975');
$code = $tmhOAuth->request("GET", $tmhOAuth->url("https://api.twitter.com/1.1/trends/place.json"), $args);
print $code;
$res = $tmhOAuth->response['response'];
$trends = json_decode($res, true);
return $trends;
}
Try removing https://api.twitter.com/ from the URL. I was getting a 404 as well until I removed that segment of the URL and am now getting a 200 response code.
I want to update my Twitter. I use tmhOAuth from themattharris . I have enabled Curl and the Twitter app settings are correct with read write access. I checked the header and requests are empty. At first the code should work just changing the key and changes in Twitter. What do you think I'm doing wrong?
require 'tmhOAuth.php';
require 'tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
// 'consumer_key' => 'YOUR_CONSUMER_KEY',
//'consumer_secret' => 'YOUR_CONSUMER_SECRET',
//'user_token' => 'A_USER_TOKEN',
// 'user_secret' => 'A_USER_SECRET',
'consumer_key' => 's8wEiEo0EFk7fCX5jHfVfw',
'consumer_secret' => 'db2qENrjCRxtaOFs9a7wT7YPjWNRxO1yHHxT9EkM',
'user_token' => '92957047-suEq4sH6ADTFXfOqrWfpbX6D9OqYGMyKA8CMAQVz4',
'user_secret' => 'LqhbQRp29M7L5UfdtJhde3kHxzB5oOn5xtGIdy35bOY',
));
$code = $tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array(
'status' => 'My Twitter Message'
));
if ($code == 200) {
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
tmhUtilities::pr($tmhOAuth->response['response']);
I am really stuck in this, and need expert help. Let me explain what I am trying achieve and the setup. I had a script which posts over a https form using Zend_Http_Client. On the server setup I have tor & privoxy running. Everything just worked fine, but now I need to make the code more scalable by running multiple instances of tor & privoxy on the same server.
Hence I shifted the Adapter for Zend from Zend_Http_Client_Adapter_Curl to Zend_Http_Client_Adapter_Proxy . But after changing the adapter I have bumped into a strange error which says - 400 Invalid header received from client and when I dump the object of Zend client, I see the following -
MyWebClientResponse::__set_state(array(
'json' => NULL,
'version' => '1.1',
'code' => 400,
'message' => 'Invalid header received from client',
'headers' =>
array (
'Proxy-agent' => 'Privoxy 3.0.19',
'Content-type' => 'text/plain',
'Connection' => 'close',
),
'body' => 'Invalid header received from client.
',
))
I do not understand what is that I am doing wrong. The code is done in Yii Framework so it is hard to share all the classes and Models, but I am sharing the main parts of the code, which are responsible for this -
$client = MyWebClient::factory();
$adapter = $client->getAdapter();
$adapter->setConfig(array('timeout' => 120,
'proxy_host' => 'localhost',
'proxy_port' => 8124
));
$client->setAdapter($adapter);
$client->setCookieJar(true);
$client->setParameterPost(array(
'name' => 'firstname',
'password' => 'password,
'login' => 'home'
));
$response = $client->setUri('https://www.domain.com/post.php')->requestApi('POST', false);
Here's the constructor of the class MyWebClient, just in case it it required, all other methods are standard.
static public function factory($new = false)
{
if (!isset(self::$client))
{
self::$client = new MyWebClient();
self::$client->setConfig(array(
'adapter' => 'Zend_Http_Client_Adapter_Proxy',
// 'proxy_host' => 'localhost',
// 'proxy_port' => 8118,
'persistent' => false,
'timeout' => 120
));
}
return self::$client;
}
The headers are being set in the requestAPI method and the snippet is -
$headers = array(
'X-PHX' => 'true',
'X-Requested-With' => 'XMLHttpRequest',
'Referer' => 'https://domain.com/index.html',
'User-Agent' => self::getRandomUserAgent()
);
$this->setHeaders($headers);
I would really appreciate help in this regard. Think it's privoxy which is not letting go the request out of the server.
Sachin
Looks like you may need to wrap the user-agent with quotes. Try this when setting the headers and see if that fixes the problem.
$headers = array(
'X-PHX' => 'true',
'X-Requested-With' => 'XMLHttpRequest',
'Referer' => 'https://domain.com/index.html',
'User-Agent' => "'".self::getRandomUserAgent()."'"
);
$this->setHeaders($headers);
Finally I decided to use the native cURL library and the cookieJar which comes with it. It worked like expected.
Cheers,
Sachin