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.
Related
I'm trying to publish tweet on twitter with image and a link to my site
I get the following error:
{"errors": [{"code": 189, "message": ". Error creating status"}]}
I tried with twitter api:
with update.json
the tweet is published but no picture.
and
update_with_media.json
I get error
this is the code I use:
require '../tmhOAuth.php';
require '../tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'xxxxxxxxxx',
'consumer_secret' => 'xxxxxxxxxxxxx',
'user_token' => 'xxxxxxxxxxxxxxxxxxxx',
'user_secret' => 'xxxxxxxxxxxxxxxxxx',
));
// we're using a hardcoded image path here. You can easily replace this with an uploaded image-see images.php example)
// 'image = "#{$_FILES['image']['tmp_name']};type={$_FILES['image'] ['type']};filename={$_FILES['image']['name']}",
$picimg="img.jpg";
$code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json',
array(
'media[]' => "#{$picimg}",
'status' => "status"
),
true, // use auth
true // multipart
);
if ($code == 200) {
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
tmhUtilities::pr($tmhOAuth->response['response']);
}
I searched a lot on google but not served me anything.
I do not understand what's going on
It was poorly cast the image url and more stuff.
I have made an example of different api in my local.
I used APIs
https://github.com/themattharris/tmhOAuth
I've also installed composer for dependencies.
installing dependencies twitter api.
Well the most important thing is:
this piece of code:
$picimg="img.jpg";
array(
'media[]' => "#{$picimg}",
'status' => "status"
)
this is wrong.
but this above is good
$image = __DIR__.DIRECTORY_SEPARATOR .'..' . DIRECTORY_SEPARATOR . 'fotos'. DIRECTORY_SEPARATOR . 'foto1.jpg';
DIRECTORY_SEPARATOR is used instead of backslash, and this is very important if not the error response would be 189
$name = basename($image);
$status = "Picture time";
$media = "#{$image};type=image/jpg;filename={$name}";
media must be represented well in this format, not only url string.
// we set the type and filename are set here as well
$params = array(
'media[]' => $media,
'status' => $status
);
This is working AMIGOS
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.”
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')
);
I am using matt harris' twitter library https://github.com/themattharris/tmhOAuth and following the image upload example.
I get a zero returned when trying to post an image with no $tmhOAuth->response['response'] being returned.
Steps i have tried
Running the example as it is- fails
Running verify ssl- works fine
Running the status update with out the image- it posts correctly as expected
swapping the url from 1 to 1.1- nothing changes, library still returns zero
It runs quite quickly implying its not even trying to post an image.
Any ideas on why this isnt working or anything i need to configure on the server
Below is the code i copied from the example to try with.
<?php
// testing hmac works- correctly
echo hash_hmac('ripemd160', 'The quick brown fox jumped over the lazy dog.', 'secret');
$tmhOAuth = array( 'consumer_key' => 'removed',
'consumer_secret' => 'removed',
'user_token' => 'removed',
'user_secret' => 'removed');
// array(
// 'consumer_key' => 'YOUR_CONSUMER_KEY',
// 'consumer_secret' => 'YOUR_CONSUMER_SECRET',
// 'user_token' => 'A_USER_TOKEN',
// 'user_secret' => 'A_USER_SECRET',
// )
require 'tmhOAuth.php';
require 'tmhUtilities.php';
$tmhOAuth = new tmhOAuth($tmhOAuth);
// we're using a hardcoded image path here. You can easily replace this with
// an uploaded image - see images.php in the examples folder for how to do this
// 'image = "#{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
// this is the jpeg file to upload. It should be in the same directory as this file.
$image = 'image.png';
$code = $tmhOAuth->request(
'POST',
'https://upload.twitter.com/1.1/statuses/update_with_media.json',
array(
'media[]' => "#{$image};type=image/jpeg;filename={$image}",
'status' => 'Picture time',
),
true, // use auth
true // multipart
);
if ($code == 200) {
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
tmhUtilities::pr($tmhOAuth->response['response']);
}
?>
The post url https://upload.twitter.com in the request should be http://api.twitter.com
i HAVE read many Tutorials on posting to twitter using OAuth like here but i am still unclear on some things.
My requirements is to tweet through multiple accounts for each of which i have a username/password.
Is this possible ? If yes then how do i do it?
I am confused how to get the 4secret keys required for each user account that i have.
1. PHP Class: https://github.com/themattharris/tmhOAuth
2. PHP Function
function tweet($status, $consumer_key, $consumer_secret, $user_token, $user_secret){
include("class.twitter.php");
$tmhOAuth = new tmhOAuth(array(
'consumer_key'=> $consumer_key,
'consumer_secret' => $consumer_secret,
'user_token' => $user_token,
'user_secret' => $user_secret,
));
$tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array(
'status' => $status
));
}
3. https://dev.twitter.com/apps/new (register an app, get keys foreach account)
4. tweet("yay!", ...);
5. goto 4 but with different keys
Read up on Twitter's authentication scheme, and then have a look at some libraries.