Twitter XML feed - php

I have just coded twitter feed for my statuses fetching the xml. I was wondering if there is any link also for XML of mentions and hashtags

For twitter mentions:
function curlRequest($url, $post) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
// we are not using the $post variable yet, but stay tuned!
if ($post) {
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
return curl_exec($curl);
}
//then call this function as:
$contents= curlRequest(“http://twitter.com/statuses/mentions.xml”, FALSE);
$xml= new SimpleXMLElement($contents);
foreach($xml->status as $status) {
echo "<li>$status->text</li>";
}

Related

What is wrong with this code. it shows "msg is null"

This the code.
$data = '{"rewardTime":"20","articleTime":"0","rewardType":"copper_treasure_chest","activeDay":"17","videoTime":"20","specific":"false","userid":"2944210","version":"3","day":"2020-05-07","token":"M2U4ZjQyMWItZmNiYi00NWM4LWJhYWYtOTZhZWEwY2ExODY5"}';
$url = 'https://api.cc.clipclaps.tv/reading/obtainReward';
$curl = curl_init();
curl_setopt($curl, CURLOPT_PORT, 443);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$result = json_decode($result, true);
echo "$result"."\n";
This is the result:
{"code":4009,"msg":null,"data":null,"date":1588991702039}
It should be msg: success
You would need to refer to the API's documentation to figure out what Error: 4009 is exactly.
Your code (Curl request) is working, as it is receiving a proper JSON response.. and there is no coding error that I see.
Why the API is responding with an empty result/data field, is specific to the API itself.

Same cURL code, different results with PHP and Laravel

When I try to save cookies without Laravel,it's saved.But with Laravel I can't find the cookie file(Searched everywhere :) ).
Here is the code(part):
...Some php code...
$dataJSON = json_encode($dataPost);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dataJSON);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie.txt"); //even with the realpath ,no difference
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($curl);
print_r($result);
curl_close($curl);
Is it a Routing problem?

why i am getting forbidden error in googleurl shotner api?

why i am getting forbidden error my code is-
$api_key="my-api-key";
$json='{
"longUrl": "honortraders-2.myshopify.com/admin"
}';
$url="https://www.googleapis.com/urlshortener/v1/url?&key=".$api_key;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($curl);
curl_close ($curl);
echo $response;*i am trying to use google urlshortner api but i am getting forbidden error*

how to send a url request in opencart using CURL method?

I am working in Opencart platform. now I am really stuck in integrating a sms api link. last few days I have done many things but I can't reach there.
I don't know what is the issue in my code. I am using CURL method:
function curl_get_contents($url)
{
$curl = curl_init();
if (substr(HTTPS_CATALOG, 0, 5) == 'https') {
curl_setopt($curl, CURLOPT_PORT, 443);
}
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_USERAGENT, $this->request->server['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
$json = curl_exec($curl);
if (!$json) {
$this->error['warning'] = sprintf($this->language->get('error_curl'), curl_error($curl), curl_errno($curl));
} else {
curl_close($curl);
}
}
this is my curl function, and I called the function like this.
$link= "http://**.**.**.**:****/sendsms/bulksms?username=****-****&password=********&type=0&dlr=1&destination=********&source=****&message=******"
$this->curl_get_contents($link);
I hope somebody will help me to survive from these problem

Parse web page without save local?

Sorry my English a little. I am using CURL because web page is required this function. I don't get file_get_contents of page. How to parse page without page save? (fopen,fwrite)
<?PHP
function fileGet($url, $timeout = 55, $ref=true){
$useri = $_SERVER['HTTP_USER_AGENT'];
#set_time_limit($timeout);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($curl, CURLOPT_COOKIE, 'PHPSESSID=fztitsfgsafafaq25llwafd0; path:/' );
curl_setopt($curl, CURLOPT_USERAGENT, $useri);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_REFERER,$url);
$data = curl_exec($curl);
curl_close($curl);
// Save Page Start
$fp = fopen('data.html', 'w');
fwrite($fp, $data);
fclose($fp);
// Save Page End
return $data;
}
// Start Code
fileGet("http://www.example.com",10); // Start Function
$html = file_get_html('data.html'); // Open Saved Page In Local
foreach($html->find('div.columns') as $article) {
// Events.....
mysql_query("Insert Query");
}
// End Code
?>
<?PHP
function fileGet($url, $timeout = 55, $ref=true){
$useri = $_SERVER['HTTP_USER_AGENT'];
#set_time_limit($timeout);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($curl, CURLOPT_COOKIE, 'PHPSESSID=fztitsfgsafafaq25llwafd0; path:/' );
curl_setopt($curl, CURLOPT_USERAGENT, $useri);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_REFERER,$url);
$data = curl_exec($curl);
return $data;
}
// Start Code
$html = str_get_html(fileGet("http://www.example.com",10));
foreach($html->find('div.columns') as $article) {
// Events.....
mysql_query("Insert Query");
}
// End Code
?>

Categories