Showing posts with label API. Show all posts
Showing posts with label API. Show all posts

Sunday 8 December 2019

Swagger - REST API documentation tool

Swagger - REST API documentation tool

Question: What is swagger?
It is REST API documentation tool which is used to list the APIs and view the request and response.
In this, we need to add some annotations in your functions and then it will automatically generate a beautiful and user-friendly documentation for your APIs.

Question: Where it is used?
Whenever we develop an android, IOS (Apple) application, we need to create an APIs for them.

To check the API details (URL, Request, response), we use Swagger.

Question: Who is using swagger?
Backend Developer: developer used it while creating Or updating an API.
Team Leader: As it give List of APIs with request and response. Team leader used it review the APIs.
Android/IOS Developer: While integrating the APIs, Its quite help the developer because they can check the response of APIs with different request.

Question: What are benefits of swagger?
  1. Its give list of APIs with short description.
  2. Its give the Request and Response of API.
  3. We can test the response of API with different request.
  4. We need to integrate in application first time, after the we need to add some annotations in functions/APIs.
  5. Can be integrate in Core PHP or Framework.
  6. We need not to list and details of apis manually.

Question: What is Swagger Editor?
The Swagger Editor is the tool for quickly getting started with the Swagger Specification.
Create new APIs OR update existing ones in a powerful Editor which visually renders your Swagger definition and provides real time error-feedback.

Question: Give a Demo URL?

Question: From where i can download?

Question: How to Add API in swagger?
Add Following code before the class declaration
 * @SWG\Resource(
 *     apiVersion="1.0",
 *     swaggerVersion="1.2",
 *     description="Search users"
 * )

Question: How to add new Operation for an API?
Add Following code before the method declaration
     * @SWG\Api(
     *     path="/search",
     *     @SWG\Operation(
     *         method="POST",
     *         summary="Get users near your location",
     *         type="Users list",
     *         @SWG\Parameters(
     *             @SWG\Parameter(
     *                 name="interests",
     *                 paramType="form",
     *                 description="comma seperated looking for",
     *                 required=false,
     *                 type="string",
     *                 minimum="1.0"
     *             ),
     *             @SWG\Parameter(
     *                 name="page",
     *                 paramType="form",
     *                 description="page number",
     *                 required=true,
     *                 type="string",
     *                 minimum="1.0"
     *             ),
     *         ),
     *         @SWG\ResponseMessage(code=400, message="Invalid Data")
     *     )
     * )

Saturday 16 November 2019

How to Send Tweets automatically with PHP?

How to Send Tweets automatically with PHP?

Basic Requirements
  1. An Twitter account.
  2. An Twitter app. If don't have please create @
  3. Twitter Auth REST API, If don't have please download from
  4. An Server, You can also test in local wampserver or xampserver

How to Send Tweets automatically with PHP, Follow following Steps:
  1. Include twitter files.
  2. Collect all constants values from your twitter app (i.e

  3. Add constants in TwitterOAuth constructor.
    define('CONSUMER_KEY', 'YOUR_KEY');
    define('ACCESS_TOKEN', 'YOUR_TOKEN');
  5. Now post the message.
    $message='This is test tweet.';
    $twitter->post('statuses/update', array('status' => $message));
  6. Refresh the, you will see your message at top of page.

Thursday 14 June 2018

Get the access token with OAuth 2.0 for Google API

Follow Below 4 steps to get the access token with OAuth 2.0 for Google API

1. Obtain OAuth 2.0 credentials ("Client ID" and "Secret Key") from the Google Developers Console.
  • Go to
  • Select your project (create new project, If not have created before).
  • Click on "APIs & auth"
  • Click to "APIs", Now you have all the list of Google APIs  .
  • Select OR Search the APIs from search box, the one which you want to use.
  • Select API and Click on "Enable API". (I enable "Google Webmaster Tools API")
  • Now, click on "Credentials", Click on "Create new Client ID" under OAuth tab.
  • Popup will come. click on "Configure consent screen".
  • New form will appear. Fill the details and click on "Save".
  • Confirmation page appear, Click on "Create Client ID"
  • Now you will see the screen simpilar to below:

 Obtain OAuth 2.0 credentials
 Obtain OAuth 2.0 credentials
  • m. Get the "client Id" and "Client secret". (DON'T SHARE IT).

2. Create a new page in PHP like
Add this URL in "Authorized redirect URIs" in your project (in Edit setting) above created.

3. Get the GET Access token from google using "Client ID" and "Secret Key"
Add the below code in "auth-url.php"
if (isset($_GET['code'])) {    
    $code = $_GET['code'];
    //Set the Auth URL
    $url = '';
    //Set the Auth Parameter
    $redirectUri='http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
    $params = array(
        "client_id" => YOUR_CLIENT_ID,
        "client_secret" => YOUR_CLIENT_SECRET,
        "redirect_uri" => $redirectUri,
        "grant_type" => "authorization_code",
        "code" => $code,

    /** Init the curl */
    $ch = curl_init();
    curl_setopt($ch, constant("CURLOPT_" . 'URL'), $url);
    curl_setopt($ch, constant("CURLOPT_" . 'POST'), true);
    curl_setopt($ch, constant("CURLOPT_" . 'POSTFIELDS'), $params);
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    if ($info['http_code'] === 200) {
        header('Content-Type: ' . $info['content_type']);
        return $output;
    } else {
        die('An error occured');
    /** Init the curl */
} else {

    $url = "";

    //Set the Auth Parameter
    $params = array(
        "response_type" => "code",
        "client_id" => YOUR_CLIENT_ID,
        "redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],        
        "scope" => "" //I have added scope for webmaster tool

    $requestTo = $url . '?' . http_build_query($params);

    //Redirect the page
    header("Location: " . $requestTo);

4. You will get result simpliar to below.
{ "access_token" : "ya29.kgGOtdWEj32NOSxLWkZXAaXAagmkP-4WgHEd8gpUfuelHD_lslquKzHMVV2OnnNc5h1BKWkY8aeCrA", "token_type" : "Bearer", "expires_in" : 3600 }

Here you got access_token, token_type and expires_in (in Seconds).

If this code does not work and need any assistance, Please feel free to comment.

Tuesday 5 September 2017

Validate Icalendar File or URL

Question: What is Desktop iCalendar?
Desktop iCalendar is a handy desktop calendar for Windows. It stays on your desktop and shows the days of the current month have the events. It can be sync with Google Calendar OR Yahoo Calendar. You can share the calendars with your family and friends with use of the Google OR Yahoo. File format of iCalendar is .ics.

Question: What is use of iCalendar?
iCalendar is a computer file format which allows Internet users to send meeting requests and tasks to other Internet users, via facebook, email. Recipients of the iCalendar data file can respond to the sender easily or counter propose another meeting date/time

Question: Why need of Validate the Icalendar?
When we validate, It make sure us that we are sharing correct and valid file. Also it make sure recipients will get the  task/events once they get.

Question: How to validate Icalendar File OR code snippt.

Question: What are Development Tools for Validate Icalender.
Language Library
C/C++ libical
Java iCal4J
Python vObject
Ruby iCalendar
Ruby RiCal

Monday 9 January 2017

How to integrate Google Places Search API in website?

How to integrate Google Places Search API in website?

Get the Google API Key
  1. Login to
  2. Get the API Keys.
  3. Enable "Google Places API Web Service" from Google Google Map API


<script src=";libraries=places&amp;key=HERE_YOUR_KEYS"></script>
<div class="search-Form">
<input id="search" name="q" type="text" value="" /> <input id="submit" type="submit" value="go" />

JavaScript Code

    var lat
    var lon
    function initialize() {
        var input = document.getElementById('search');
        var autocomplete = new google.maps.places.Autocomplete(input);

        google.maps.event.addListener(autocomplete, 'place_changed', function() {
            var place = autocomplete.getPlace();
            lat =
            lon = place.geometry.location.lng()


    google.maps.event.addDomListener(window, 'load', initialize);

View Demo