Twitter request exceed issue - twitter

Twitter request exceed problem. It shows requests exceed 150 per hour.
This is my code :
$trends_url = "https://api.twitter.com/1/statuses/friends.json?screen_name=".$_SESSION['Auth']['User']['screen_name'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $trends_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlout = curl_exec($ch);
curl_close($ch);
$response = json_decode($curlout, true);
I am using PHP curl to get Twitter friend list. If I manuaaly post this URL in browser like "https://api.twitter.com/1/statuses/friends.json?screen_name=Rock_Feather".
It works fine, but not giving data back while using curl.

Related

How to send bulk messages using twillo notify API via CURL in php?

I want to send bulk messages using twillio notify API using CURL in php I'm trying below Code :
$data = [];
$data['ToBinding'] = array("binding_type"=>"sms", "address"=>"+12013318779");
$data['Body'] ="test";
$ch = curl_init("https://notify.twilio.com/v1/Services/ISXXXXXXXXXXXXXXXXXX/Notifications");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_USERPWD,'XXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXX');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$resultData = curl_exec($ch);
I think I'm doing something wrong with the CURLOPT_POSTFIELDS but I tried each and every thing to change that but every time I got the below response :
{"code": 20001,
"message": "At least one parameter among Identity, Tag, and ToBinding must be specified",
"more_info": "https://www.twilio.com/docs/errors/20001",
"status": 400}
Can you guys please help me out.
Thanks
Twilio developer evangelist here.
ToBinding requires the data to be encoded as JSON. Try the following:
$data['ToBinding'] = json_encode(array("binding_type"=>"sms", "address"=>"+12013318779"));
Hope that helps.

Pentaho REST API: Issue when using Pentaho Cookie-Based Authentication

Been struggling with this for a while, so any help is really appreciated...
I have Pentaho reports loaded into Pentaho Server. These reports are called via an Iframe.
What I'm trying to do is have the user authenticate one time only, so he can run other reports without having to reauthenticate. For that, I use Pentaho Cookie-Based Authentication as documented here: https://help.pentaho.com/Documentation/8.0/Developer_Center/REST_API
My issues are:
1) I wrote a small php script that sends a POST request to /pentaho/j_spring_security_check. The scripts does not return any error, but does not redirect me to home page as expected.
<?php
$data = array("j_username"=>"admin", "j_password"=>"password",
"locale"=>"en_US");
$string = http_build_query($data);
echo $string;
$ch =
curl_init("http://localhost:8080/pentaho/j_spring_security_check");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $ch;
$return = curl_exec($ch);
echo $return;
if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
?>
2) I tried typing directly in the browser "http://localhost:8080/pentaho/j_spring_security_check?j_username=admin&j_password=admin", I get the "login_error=1" result, while both logins and passwords are correct (the expected behaviour is to be redirected to the home page).
It's the first time I'm using REST API, so I might be doing things wrong.
Many thanks
answered here: https://community.hitachivantara.com/thread/14811-pentaho-rest-api-issue-when-using-pentaho-cookie-based-authentication
I was missing the step where I would reuse that cookie.
Also, using "curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true)" helped me understand mistakes in my script and solve it.
Correct script is:
<?php
$data = array("user"=>"admin", "password"=>"admin");
// $string = http_build_query($data);
// echo $string;
$cookie_jar = tempnam('/Users/pierre/Vrac','cookie');
if (!file_exists(realpath($cookie_jar))) touch($cookie_jar);
$ch = curl_init("http://localhost:8080/pentaho/j_spring_security_check?
j_username=admin&j_password=admin&locale=en_US");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
//echo $ch;
$return = curl_exec($ch);
echo "execution report";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($ch, CURLOPT_URL,'http://localhost:8080/pentaho/api/repos/:public:IframeDossier:IframeTest.prpt/viewer?label=fin');
$page = curl_exec($ch);
echo $page;
curl_close($ch);
?>

Not getting survey info in an SurveyMonkey API call

I'm trying to get the entered information on a survey of SurveyMonkey through the API. But i'm getting the following return message: "Could not validate access to survey at this time, please try again later.", with status 5 (System Error).
I'm working with a APP in Draft status. All the scopes in my app are put on optional. And other api calls (like get_survey_list) do give me data.
I'm working with php, but the API console (https://developer.surveymonkey.com/docs/api_console/) also gives me these results.
Is there an extra permission layer i'm missing? Do ppl need to approve something through oauth?
The API console is for V2 of the API (which is either deprecated, or likely to be deprecated soon), I would recommend using V3 (https://developer.surveymonkey.com/api/v3)
You can fetch the list of surveys using
GET /v3/surveys
And you can get a specific survey with
GET /v3/surveys/<id>
And follow down the path to get individual pages/questions, or if you want the entire survey expanded at once, use:
GET /v3/surveys/<id>/details
With regards to the request you are doing with API v2, I'd probably need a bit more information, if you are doing a POST with an empty body to get_survey_list and are getting that issue I'd probably contact their customer support to look into it as it looks like a server error. But I would recommend going to V3 and see if everything works fine for you.
Like the general posted, v3 works fine. Here is the code of my POC that works:
// GET USER
$requestHeaders = array(
'Content-Type: application/json',
'Authorization: Bearer [ACCESS_TOKEN]',
);
$url = 'https://api.surveymonkey.net/v3/users/me?api_key=[API_KEY]';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
$result = curl_exec($ch);
curl_close($ch);
The above is the just a simple call to get the basic info of the user.
The next call get's the answers given in the responses that are given through a specific collector.
// GET THE ANSWERS OF THE SURVEY
$requestHeaders = array(
'Content-Type: application/json',
'Authorization: Bearer [ACCESS_TOKEN]',
);
$url = 'https://api.surveymonkey.net/v3/collectors/[COLLECTOR_ID]/responses/bulk?api_key=[API_KEY]';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
$result = curl_exec($ch);
curl_close($ch);
You can also import the API into Postman. There is a button for this on the documentation site. Pretty nice :)

How to get list of all active jira issue list?

I want to know how to get list of all active jira issues through rest api. Once when i get the list I am planning on using si/jira.issueviews:issue-xml feature in the uri to download all issues in xml format. But I do not have the list of all the issues. I have googled and only came up with answers that has to do with getting issues under a specific project.
This is how I do a search using cURL and the REST API in PHP:
$url = "http://YOUR_SERVER_URL_AND_PORT/rest/api/2/search";
$data = array("jql" => "status not in (Closed, Resolved, Done)","startAt" => 0,"maxResults" => 200);
$httpHeader = array(
'Accept: application/json',
'Content-Type: application/json'
);
try{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "USER_NAME:USER_PASS");
$result = curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error == '')
$out = $result;
else
$out = json_encode(array('error' => $ch_error));
}catch(Exception $e){
$out = json_encode(array('error' => $e->getMessage()));
}
curl_close($ch);
You need to change YOUR_SERVER_URL_AND_PORT, USER_NAME and USER_PASS with your own information.
NOTE: the previous REST query will only return issues that you are allowed to see. If you need to see ALL issues, you need to provide Jira Admin credentials in your cURL config.

Getting feedburner subscriber count

Can someone tell me how can I get the feedburner subscribers count as text using php? I am trying the following, but it does not work as I think feedburner has changed the contents of the xml file.
Thanks for any help.
$whaturl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=USERNAME";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $whaturl);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry['circulation'];
echo $fb;
Need to alter line 7 to:
$fb = $xml->feed->entry->attributes()->circulation;
//Much later edit
I actually have a couple of posts on my blog by now with code for fetching facebook / twitter / feedburner counts. Code with APC caching is here:http://www.glowingminds.co.uk/facebook-likes-twitter-follows-and-feedburner-count-in-php-with-curlsimplexml-deluxe/

Resources