0

up until today the below code was working fine, however, now it has stopped working. Yet if I put the URL in it returns a feed. Any idea what is going on here? I tried to debug Curl with error handling.

<?php
if (!isset($_GET['page']))
    {
    $page = '&page=1';
    }
else
    {
    $page = '&page=' . $_GET['page'];
    }
$curl_handle = curl_init();
//return the transfer as a string 
curl_setopt($curl_handle, CURLOPT_URL, 'http://www.behance.net/v2/users/andrewwelch/projects?api_key=XXX' . $page);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5);
if(!curl_exec($curl_handle)){
    die('Error: "' . curl_error($curl_handle) . '" - Code: ' . curl_errno($curl_handle));
}
$query = curl_exec($curl_handle);
curl_close($curl_handle);
$projects = (json_decode($query));
;
$i = 0;
$projcount = array();
if (isset($projects))
    {
    foreach (reset($projects) as $value)
        {
        if ($i % 4 == 0)
            {
            if ($i != 0)
                {
                print "</div>";
                }
            print '<div class="row">';
            }
        print '<div class="col-sm-3" style="height:200px;">';
        $covers = (Array) $value->covers;
        print '<a href="' . $value->url . '" target="_blank">';
        $thiscover = array_slice($covers, '1');
        print '<img src="' . reset($thiscover) . '"/>';
        print '<span class="thumb_title">' . $value->name . '</span>';
        print '</a>';
        print '</div>';
        $i++;
        }
    print "</div>";
    $pagenumber = $_GET['page'];
    $prevpagenumber = ($_GET['page'] == 1) ? ($_GET['page']) : ($_GET['page'] - 1);
    if (!($i < 12))
        {
        print '<a class="next-butt" style="float:right; display:inline" href="http://www.andrewwelch.info/web.php?page=' . ($_GET['page'] + 1) . '">Next page >></a>';
        }
    if (($_GET['page']) > 1)
        {
        print '<a class="prev-butt" href="http://www.andrewwelch.info/web.php?page=' . $prevpagenumber . '"><< Previous page</a>';
        }
    }
else
    {
    print 'No projects available.';
    }
?>
1
  • Might not want to post your API key in a live forum Commented Dec 5, 2013 at 13:19

1 Answer 1

1

I had the same problem and was getting a connection timed out...but discovered I wasn't setting the User-Agent. Apparently you have it in your code.

What happens if you put this http://www.behance.net/v2/users/andrewwelch/projects?api_key=XXX on your browser?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.