I am trying to query stackoverflow and route it to my website via the following

require_once './stackphp_source_0.4/src/api.php';
require_once './includes/function.php';

// Begin by getting a Site object for Stack Overflow.
// We can use 'stackoverflow' or 'stackoverflow.com' here.

$question = new QuestionRequest('http://www.stackoverflow.com', null);
$question = $question->Search("C#");

// paged Response object
$page = $question->Answers()->Exec(); 


          <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>Stack.PHP - User's Questions</title>
  <!-- <link rel='stylesheet' type='text/css' href='../common/style.css' /> -->

        <?php include("includes/banner.php"); ?>
        <div class="main_content">
              <h2>Questions Asked By User #1 on Stack Overflow</h2>
              <?php echo $page->Fetch(); ?>

    <?php include("includes/script_includes.php"); ?>

I keep getting the error

Curl was unable to retrieve the data from the specified URL.


First of all, you should be using the latest version of Stack.PHP, which is version 0.5. You can download a tarball here:


The only file you need to include is api.php which is in the src/ directory.

You will almost never need to create a Request object yourself since you can obtain it from a Site object. You can do that with:

$site = API::Site('stackoverflow');

Now you can use $site to access the methods available on that site, most of which return a subclass of Request:

$request = $site->Search('C#');

Once you have a request, you need to convert it into a response. This is done as follows:

$response = $request.exec();

You can then enumerate the items in the response with:

while($q = $response->Fetch(FALSE))
    // do something with $q here

For example, echo $q['title'] will display the question's title.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .