skip to Main Content

All I want to post an image on the instagram using Oauth2 & PHP pretty similar like wall post for Facebook and Tweet post for Twitter like:

User click on share on Instagram button from my website, they redirect to the Instagram app approval page, they approve and the image gets posted on their account.

I have searched almost entire internet for this requirement. But I didn’t get exact code to achieve this.

I have already checked these:

https://github.com/mgp25/Instagram-API

https://github.com/cosenary/Instagram-PHP-API

Some people says that it is not possible, Instagram doesn’t allow that.

So all I want is a clear answer whether is it possible or not? If yes then how?

Thanks

2

Answers


  1. Clear answer

    It’s not possible and not official in any way. All the Unofficial APIs / packages / libraries… whaterver you might find are barely tentatives of reverse engineering of the traffic generated by the Instagram App.

    So they might work for a while, but then Instagram will block them.

    Think about it. If there’s somewhere an official way to upload stuff to instagram there will be a lot of alternative apps and spammers using it.

    If you don’t believe me, check the official API documentation. There’s no reference to the upload of pictures.

    Login or Signup to reply.
  2. Post istagram image with caption using facebook api(business account - without login) 
    ref - https://github.com/facebookarchive/php-graph-sdk
    
    <?php 
    define('FACEBOOK_SDK_V4_SRC_DIR', __DIR__.'/src/Facebook/');
    require_once(__DIR__.'/src/Facebook/autoload.php');
        $instaData = [
                     'image_url' => 'image_url',
                     'caption' => htmlspecialchars('your message')
                     ];     
    $pageAccessToken ='your access token';
    $fb = new FacebookFacebook([
     'app_id' => 'fb_app_id',
     'app_secret' => 'app secrect',
     'default_graph_version' => 'v12.0',
    ]);
    try {
     $response = $fb->post('INSTA_PAGE_ID/media/?', $instaData, $pageAccessToken);
    } catch(FacebookExceptionsFacebookResponseException $e) {
     echo 'Graph returned an error: '.$e->getMessage();
     exit;
    } catch(FacebookExceptionsFacebookSDKException $e) {
     echo 'Facebook SDK returned an error: '.$e->getMessage();
     exit;
    }
    $graphNode = $response->getGraphNode();
    $creation_id = json_decode($graphNode);
    $publish_image = [
                     'creation_id' => intval($creation_id->id)
                    ];
    try {
     $response1 = $fb->post('INSTA_PAGE_ID/media_publish/?', $publish_image, $pageAccessToken);
    } catch(FacebookExceptionsFacebookResponseException $e) {
     echo 'Graph returned an error: '.$e->getMessage();
     exit;
    } catch(FacebookExceptionsFacebookSDKException $e) {
     echo 'Facebook SDK returned an error: '.$e->getMessage();
     exit;
    }
    echo "<pre>"; print_r($response1); echo "</pre>";
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search