Require once/include in my laravel project is not functioning properly. I am using the correct path however i continue to get the same error. I can see the file is in the designated space. What could cause this? Here is my code:
#extends('apps.admin')
#section('main')
<?php
include(app_path().'vendor/j7mbo/twitter-api-php/TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "token",
'oauth_access_token_secret' => "token",
'consumer_key' => "token",
'consumer_secret' => "token"
);
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=#nerd';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
var_dump(json_decode($response));
?>
#stop
I also tried this:
require_once('vendor/j7mbo/TwitterAPIExchange.php');
and this:
require_once('TwitterAPIExchange.php');
errors:
include(/var/www/web/elephantegin/htdocs/app/vendor/j7mbo/twitter-api-php/TwitterAPIExchange.php): failed to open stream: No such file or directory (View: /var/www/web/elephantegin/htdocs/resources/views/socialApps/twitter.blade.php)
errror:
main(): Failed opening required '/vendor/j7mbo/TwitterAPIExchange.php' (include_path='.:/usr/share/php:/var/www/web/elephantegin/htdocs')
You are referencing the file incorrectly, use the correct path:
include(app_path().'../vendor/j7mbo/twitter-api-php/TwitterAPIExchange.php');
Related
I'm trying to display tweets for a specific hashtag. The code below works perfectly what ever the hashtag is, but when i try with the specific one, it doesn't work. For the last month, it worked perfectly with the right hashtag but since yesterday it's broken. (i didn't put my tokens in the code)
require_once('twitter-api-php-master/TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "my_tokens",
'oauth_access_token_secret' => "my_tokens",
'consumer_key' => "my_tokens",
'consumer_secret' => "my_tokens"
);
$hashtag = 'smartspend_eu';
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = "?q=#$hashtag";
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
The response is :
{"statuses":[],"search_metadata":{"completed_in":0.053,"max_id":1105019731759656961,"max_id_str":"1105019731759656961","query":"%23SMARTSPEND_EU","refresh_url":"?since_id=1105019731759656961&q=%23SMARTSPEND_EU&include_entities=1","count":15,"since_id":0,"since_id_str":"0"}}
What is the problem, and what can i do to fix it ?
I finaly found what's wrong. My code was right from the begining. The problem is that it's impossible to get the tweets from more than 7 days ago. And no tweets has been written for my hashtag for the last 7 days.
So what I'm doing is using the Twitter RestAPI to get the picture of a user and just be able to display the image on a local page. I've figured out the way to grab the URL of the image and this is what I have so far:
$url = $result->profile_image_url;
This holds the url of the profile picture of the user. Now how do I use this url to display it on the page? I know HTML allows us to do something like :
<img src = "some url">
And it will display the picture on the web page. I've looked around the internet for a while now, and still haven't figured it out. I've run into the same suggestion of the following :
<img src = "<?php echo ($url); ?>"/>
But I keep getting a parse error when I attempt loading the page. I would really appreciate if someone could guide me/help me figure out what's going on. Clearly, I'm doing something wrong which is why the PHP interpreter is not able to parse the code. Thanks!
Here is my whole code (if that helps):
<html>
<body>
<?php
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "N/A",
'oauth_access_token_secret' => "N/A",
'consumer_key' => "N/A",
'consumer_secret' => "N/A"
);
$url = 'https://api.twitter.com/1.1/users/show.json';
$getfield = '?screen_name=kobebryant';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$result = json_decode($json);
$url = $result->profile_image_url;
<img src = "<?php echo ($url);?>"/> //This is the line giving me an error
?>
</body>
</html>
You closed the php tag too late. That is why it is recommended to split php from html. Try this code below:
<?php
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => 'N/A',
'oauth_access_token_secret' => 'N/A',
'consumer_key' => 'N/A',
'consumer_secret' => 'N/A'
);
$url = 'https://api.twitter.com/1.1/users/show.json';
$getfield = '?screen_name=kobebryant';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$result = json_decode($json);
$url = $result->profile_image_url;
?>
<html>
<head></head>
<body>
<img src="<?php echo ($url);?>"/> //This is the line giving me an error
</body>
</html>
Hint: if you've just a string without variables use ' instead of " because php tries to parse content between " and this is waste of CPU power.
I've tried almost every solution I could find - nothing is working. Basically, the status gets updated but the media_ids parameter gets ignored.
I'm using the TwitterAPIExchange.php library. Here is my code:
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$postfields = array(
"media_ids" => 586556953049956353,
"status" => "So we keep truly! testing!"
);
$requestMethod = 'POST';
echo $twitter->setPostfields($postfields)
->buildOauth($url, $requestMethod)
->performRequest();
I want to print all the tweets from the reply. What am I missing?
https://github.com/J7mbo/twitter-api-php
<?php
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => "",
'consumer_secret' => ""
);
/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=%23twitter';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
foreach ($response->statuses as $tweet) {
echo $tweet->text;
}
Notice: Trying to get property of non-object in
/var/www/projects/twitter/twitter-api-php/index.php on line 23
Warning: Invalid argument supplied for foreach() in
/var/www/projects/twitter/twitter-api-php/index.php on line 23
The performRequest() method returns a JSON string, not an array, so you need to decode it $array = json_decode($response, true);.
You just have to use:
`echo $response;`
or instead:
echo $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
but I recommend using the first approach.
I have a PHP script that displays Tweets embedded in a site I built out on my local machine. When I uploaded the site to my IIS 8.0 server, the PHP script no longer works and I receive this error:
Warning: Invalid argument supplied for foreach() in C:\inetpub\wwwroot\i360_new\footer.php on line 76
The script is:
<?php
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "xxxxx",
'oauth_access_token_secret' => "xxxxx",
'consumer_key' => "xxxxx",
'consumer_secret' => "xxxxx"
);
/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$getfield = '?screen_name=interactive360&count=1';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
foreach($string as $items)
{
echo $items['text']."<br />";
}
?>
I thought it might be a PHP version issue but my local machine is running 5.4.10 and my server is running 5.4.14.
It turns out this was an SSL/CURL issue. In the TwitterAPIExchange.php file, I had to add these two lines to the CURL options array:
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false