PHP Behance API Tutorial with Example

By Hardik Savani November 5, 2023 Category : PHP Bootstrap Behance API

Today, i am going to share with you how to use behance api in php project. In this article i will explain how to get projects from behance website using their api in your php website or any framework application like laravel, yii2, codeigniter etc.

Behance is a networking website and it is very popular website. Behance through you can self promotion like you can make your portfolio and projects in details with title, description, category, images etc. Behance most of the famous for self-promotion.

So, today we will learn how to use behance api in php, If you don't know more about how to use api then not big issue, i will explain from scratch and give you very simple example to getting projects from username of behance. So you have to just follow three steps in this example as listed bellow:

1.Download API Files

2.Create API Key

3.Create index.php File

So, you have to just follow this three steps and you will get layout as listed bellow, and you can also check demo and download full script of source code from bellow:

Preview:

Step 1: Download API Files

In first step we have to download Behance Network API library from GitHub, So first let's download from here :
Click Here to download PHP Behance API
After download extract it to your root folder and rename it to "api".

Step 2: Create API Key

In second step you have to simple open bellow link and register your app on behance developer account they will provide app key and you can use it on your bellow example:

Register App From Here

Step 3: Create index.php File

Ok in the last step, we have to make index.php file on root directory and you have to add you "app key" on $apiKey variable. So let's create index.php file and put bellow code on that file:

index.php

<?php


require_once( 'api/src/Client.php' );


$apiKey = "your api key paste here";

$apiUsername = $_GET['username'];


$client = new Behance\Client($apiKey);


if(!empty($apiUsername)){

$data = $client->getUserProjects($apiUsername);

}else{

$data = [];

}


?>


<!DOCTYPE html>

<html>

<head>

<title>PHP - Behance API</title>

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

</head>

<body>


<div class="container">

<h1>PHP - Behance API</h1>


<form method="GET">

<div class="input-group">

<input type="text" class="form-control" name="username" placeholder="Search Behance Username">

<span class="input-group-btn">

<button class="btn btn-default" type="submit">Submit</button>

</span>

</div><!-- /input-group -->

</form>

<br/>


<table class="table table-bordered">

<tr>

<th>Project Id</th>

<th>Project Name</th>

<th>Project Image</th>

</tr>

<?php if(!empty($data)){ ?>

<?php foreach($data as $k => $value){ ?>

<tr>

<td><?php echo $value->id; ?></td>

<td><?php echo $value->name; ?></td>

<td>

<?php

if(!empty($value->covers->original)){

echo "<a href='".$value->covers->original."' target='_blank'>View Image</a>";

}

?>

</td>

</tr>

<?php } ?>

<?php }else{ ?>

<tr>

<td colspan="5">There are no data.</td>

</tr>

<?php } ?>

</table>

</div>


</body>

</html>

Ok, now we are ready to run this example, so just run bellow command on root folder for run your project.

php -S localhost:8000

Now you can open bellow url on your browser:

http://localhost:8000

I hope it can help you...

Shares