I have a review board running on different server . I am using review board as a normal user of it and can comment on the reviews create it but i am not the admin f it. In order to view the review request or comment on it, i need to authenticate with it with my username and password. This is the access given to me. Review Board is an open source tool which is used by many organisations.
Here are the WEB API of it:- (authenticating link) http://www.reviewboard.org/docs/manual/1.5/webapi/2.0/authenticating/#logging-in
Now i am using wamp as server on my local system . I am using php as server side language. I want to use the Review Board API for fetching the data with my credientals. I am using php curl and written this code for authenticating:-
<?php
$ch = curl_init('http://SERVERIP');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Basic realm="Web API"'));
$output = curl_exec($ch);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Basic md5encryptedusernamepassword'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
var_dump($info);
curl_close($ch);
var_dump($output);
?>
This code is not authenticating. Please have a look. Any kind of guideline will be helpful. I have spent much time understanding it. Please help.
You should set headers with key:"Authorization",value:" Basic #{Base64.encode64("username:password")}"。
Then you can access the api which is need authentication.
Related
I need to fetch data from this web page Sender score
.I try to use cURL but it renders white page.
Here is my code :
$ch = curl_init();
$keyword = "an-example.com";
curl_setopt($ch, CURLOPT_URL, 'https://www.senderscore.org/lookup.php?lookup='.$keyword.'&validLookup=true');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
print_r($data);
curl_close($ch);
any idea ?
Regards.
You're getting a blank page because of the captcha which is needed to fill in. Perhaps senderscore has an API which you can use? Or maybe there's another website available doing the same thing. I thought this was about scoring email statusus right? Then maybe this site will help you out: http://www.reputationauthority.org/domain_lookup.php?ip=somedomain.nl&Submit.x=0&Submit.y=0&Submit=Search
I can use this site without the need of captcha or any other bot interference.
I'm trying to use the twitter api to make a login to my website this is my first time using any api so its really confusing for me i have read a bit online searching how to make the OAuth and found a project on git-hub which allows us to connect but this will not help me to learn php so i tried the twitter documentation and found this page. The diagram in that page shows that i should post the data to the twitter api urls again searched for on google and found a stackoverflow question but don't know how to use this is there any other tutorial or book that explains all of this? This is what i understood from reading the twitter documentation if im wrong please help me rectify my mistake
Your have to first get a request token.
Try this method, it should work (not tested) :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.twitter.com/oauth/request_token');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$clientSecret);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($yourPost));
$response = curl_exec($ch);
Then follow the instruction of step 2 using CURL with GET
I am a newbie to the whole concept of the Bigcommerce Api, but my php programming is good.
I am having problems with identifying where to start exactly if i am going to integrate the php code that I may have created with the bigcommerce api,
Where do my files go? How do they interact exactly...
On the Bigcommerce site, they define what its all about, and provide the basic php codes.
Google is my friend but she hasn't been able to help me with links for the whole "How to get started" part...
Or maybe I am asking her the wrong questions.
My ultimate task is to take data from an xml file and use php to handle the rest of the processing and displaying..
I am a newbie and I am not sure how it really works. But links to proper tutorials will really help
Apparently i had no idea Big-commerce doesn't need me to host any server code on their side or whatever,
i found out that which ever code i write is simply run on my side so i can interact with my store.
i wonder why i couldn't really find this information anywhere easily, shouldn't it be the first thing we see when we reach the developers page on bigcommerce.com??
Anyway, i found what i was looking for and i understand how it works now.
To begin, as far as where do your PHP scripts go, those will be hosted external to your Bigcommerce store from any server that has PHP installed or from your local computer. The Bigcommerce API basically gives you a way to access and make changes to your store's database using a program. You will interact with API resources endpoints (URLs) which have been tied to specific store related data, like your products or orders. You can make GET, PUT, POST, and DELETE requests on these URLs in order to pull, modify, create, or delete store related data, respectively.
the php files are here https://github.com/bigcommerce/bigcommerce-api-php ,
and these should be in your machine with a PHP server
to get started there are sample codes there also.
i had problems with this line
require 'vendor/autoload.php';
so i changed it to
require 'path_to_this_file/bigcommerce.php';
everything is working fine now...
but iam still learning more
Have a look at this Link for the list of Resources.
Your php file will be making calls to BigCommerce API, to get data from BigCommerce Store.
Simple cURL snippet to get orders.
$api_url = 'https://YOUR-API-PATH.mybigcommerce.com/api/v2/orders.json';
$ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $api_url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array ('Accept: application/json', 'Content-Length: 0') );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_USERPWD, "YOUR-USERNAME:YOUR-API-TOKEN" );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$response = curl_exec( $ch );
$result = json_decode($response);
print_r($result);
Hope this helps.
For that you can not make directly call to your store front..for that make request from third party server to get your store Api.
call bellow php code by Ajax request...
like that..
----------Php Code:-
$username='username';//API User name
$password='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';//API Token
$URL='https://store-xxxxxxx.mybigcommerce.com/api/v2/products';//API path
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:UTF-8','Accept: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); code
$result=curl_exec ($ch);
curl_close ($ch);
print_r($result);//Your Requested Data
I am still fairly new at playing with PHP. I wanted to poke at a small project. I have the ability to access an xml feed from our calendar system at work. The feed requires authentication with a username and password. I am trying to automate pulling this feed. My hope is to one day use it to automate the scheduling of another system but for now I'm just trying to get this side working.
I have read through some of the cURL documentation on php.net. I have also searched through stackoverflow for a few examples. They were helpful in getting me started but not much further. Below is what I have so far. But all I get back is:
UNAUTHORIZED The request requires
authorization
So I'm racking my head to figure out what might be the issue. Part of my problem I'm sure is my ignorance with the actual process behind what is going on between the client and server. When I interact with it normally I just go to the feed URL, the browser prompts me for a username and password, and then after putting that in it gives me an xml page.
I've checked for most of the formatting errors and syntax errors I knew to look for. That may still be it but at this point I think it's more my lack of understanding how it all fits together. Thanks for any help.
Similar issues:
Parsing XML data with Namespaces in PHP
CURL HTTP Authentication at server side
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://somesight.someplace.edu/r25ws/servlet/wrd/run/events.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
I figured it out on my own after looking at a similar tutorial for Twitter. I tried a different approach to formatting the options and it worked fine. I also cut down on the number of options I was sending because it seemed like overkill. Code that works below.
<?php
$username = 'myusername';
$password = 'mypassword';
$datecall = curl_init("http://somesite.someplace.edu/r25ws/servlet/wrd/run/events.xml");
curl_setopt($datecall, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($datecall, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($datecall);
echo $result;
?>
I am unable to tweet continuously in twitter - every three tweets I get:
Error posting to Twitter. Retry
How do I fix this?
My code is as follows:
$host = "http://twitter.com/statuses/update.xmlstatus=".urlencode(stripslashes(urldecode($message)));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
$result = curl_exec($ch);
// Look at the returned header
$resultArray = curl_getinfo($ch);
//print_r($resultArray);
if($resultArray['http_code'] == "200"){
$twitter_status='Your message has been Tweeted';
update_tweet_extra($result_id,"1");
} else {
$twitter_status="Error posting to Twitter. Retry";
// update_tweet_extra($result_id,"0");
}
echo $twitter_status;
You can't use API with basic authentication since 31 august 2010. You can use a small spider function with curl that login in, fetch your home, and tweet. I made it:
http://www.barattalo.it/2010/09/09/how-to-change-twitter-status-with-php-and-curl-without-oauth/
If you don't want to use oAuth authentication model you have to do this way.
I don't think this is a problem with your code, but more the fact that Twitter is phasing out basic authentication support and moving to OAuth.
There's more information at http://apiwiki.twitter.com/Authentication.
This seems very odd, since status updates via the Twitter API are not rate-limited (see here), unless you're updating more than 1000 times a day.
You might work out more of what happened if you uncomment that helpful looking line:
//print_r($resultArray);
by removing the // at the beginning of line.
to tweet using twitter you will need a post_authenticity_token along with your username and password.
this token can be obtained from your profile page by fetching it using curl (after you login with curl). i experimented with curl and was able to tweet using curl. you can find my code at (though it is in bash script, it can be ported to php easily coz they both use curl)
http://pastebin.com/a5eBcEeP .
You can find a list of PHP libraries that support OAUTH and you can use to write a tweet function in PHP and the 1.1 version of the Twitter API here:
https://dev.twitter.com/docs/twitter-libraries
tmhOAuth is probably my favorite.