• Stars
    star
    120
  • Rank 287,551 (Top 6 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Instagram plugin for PhoneGap/Cordova

Instagram plugin for Cordova

By Vlad Stirbu.

Adds ability to share the content of a canvas element or a dataUrl encoded image using the Instagram application for iOS and Android.

GitHub version Join the chat at https://gitter.im/vstirbu/InstagramPlugin

Installing the plugin to your project

If you use cordova-cli newer than 5.0:

cordova plugin add cordova-instagram-plugin

or, for older versions:

cordova plugin add https://github.com/vstirbu/InstagramPlugin

Instagram plugin JavaScript API

Detect if the Instagram application is installed on the device. The function isInstalled accepts a callback function as parameter:

Instagram.isInstalled(function (err, installed) {
    if (installed) {
        console.log("Instagram is", installed); // installed app version on Android
    } else {
        console.log("Instagram is not installed");
    }
});

Share the content of a canvas element or a base64 dataURL png image. The function share accepts a string, corresponding to the canvas element id or the dataURL, an optional caption, and a callback function as parameters:

API CHANGE NOTE: Instagram app stopped accepting pre-filled captions on both iOS and Android. As a work-around, the caption is copied to the clipboard. You have to inform your users to paste the caption.

Instagram.share(canvasIdOrDataUrl, caption, function (err) {
    if (err) {
        console.log("not shared");
    } else {
        console.log("shared");
    }
});

or:

Instagram.share(canvasIdOrDataUrl, function (err) {
    if (err) {
        console.log("not shared");
    } else {
        console.log("shared");
    }
});

Share library asset image or video. The function shareAsset (iOS only) accepts a string with asset local identifier, and a callback function as parameters:

var assetLocalIdentifier = "24320B60-1F52-46AC-BE4C-1202F02B9D00/L0/001";
Instagram.shareAsset(function(result) {
            console.log('Instagram.shareAsset success: ' + result);
        }, function(e) {
            console.log('Instagram.shareAsset error: ' + e);
        }, assetLocalIdentifier);

You can get a LocalIdentifier by using Photos Framework Fetching Assets API

A very basic application that uses the plugin can be found here.

Additionally for IOS only, you can utilize a fourth parameter on the base64/canvas method share, to correspond with a mode:

console.log(Instagram.SHARE_MODES);
> {
    DEFAULT: 0, // original plugin logistics, where it checks for IOS Version 13+ to switch from IG to IGO mode. 
    IGO: 1, // legacy UTI for instagram DI  (.exclusivegram)
    IG: 2,  // new UTI for instagram DI  (.photo)
    LIBRARY: 3 // save base64 or canvas to disk jpg, copy it to the Library, so that it can then be shared via App Intent
}

Using above as definition, you can change your code as such (note the usage of a blank caption, to specify 4 total arguments, not 3):

var caption = ''; // copied to clipboard by Cordova js. Instagram doesn't support feeding it anymore. 
Instagram.share(canvasIdOrDataUrl, caption, function (err) {
    if (err) {
        console.log("not shared");
    } else {
        console.log("shared");
    }
}, Instagram.SHARE_MODES.LIBRARY);

AngularJS/Ionic

The plugin is included in ngCordova and ionic-native.

NOTE: If you are using an image from the server,then you should download the image and fetch the content using readAsDataURL. Example:

var url = encodeURI('https://static.pexels.com/photos/33109/fall-autumn-red-season.jpg');
var filename = 'image.jpg';
var targetPath = cordova.file.externalRootDirectory + filename;
$cordovaFileTransfer.download(url, targetPath, {}, true).then(function(result) {
        var mywallpaper = result.toURL();
        window.resolveLocalFileSystemURL(mywallpaper, function(fileEntry) {
            fileEntry.file(function(file) {
                var reader = new FileReader(),
                    data = null;
                reader.onloadend = function(event) {
                    data = reader.result;
                    $cordovaInstagram.share(data, '#amazing').then(function(success) {
                        console.log('shareViaInstagram Success', success);
                    }, function(err) {
                        console.log('shareViaInstagram failed', err);
                    });
                };
                reader.readAsDataURL(file)
            });
        });
    },
    function(error) {},
    function(progress) {
});

Quirks:

Android

  • Passing caption in addition to sharing image requires Instagram Android application version 6.1.0 or higher.
  • Older versions of Android (2.x-3.x) do not have proper support for toDataURL on canvas elements. You can still get the canvas content as dataURL following these instructions. Pass the dataUrl instead of the canvas id to share.

iOS

  • Although the plugin follows the instructions to show only Instagram in the document interaction controller, there are reports that other apps appear in the list.

Recipes

  • Sharing image when knowing the file url.

License

The plugin is available under MIT license.

More Repositories

1

fsm-as-promised

A finite state machine library using ES6 promises
JavaScript
460
star
2

vscode-mermaid-preview

Previews Mermaid diagrams
JavaScript
137
star
3

ZeroConf

ZeroConf plugin for Cordova/Phonegap 3.0
Java
39
star
4

PromisesPlugin

ES6-Promises polyfill for Cordova/PhoneGap
Shell
26
star
5

fsm-viewer

View finite state machines using fsm-as-promised library as UML diagrams in VSCode
JavaScript
23
star
6

mongoose-jsonschema

Mongoose schema to JSON schema and back
JavaScript
11
star
7

fsm2dot

Convert javascript state machine to UML diagram
JavaScript
11
star
8

dtmf

Experimenting with Web Audio API
JavaScript
8
star
9

instagramplugin-example

Basic Cordova application that demonstrates the use of InstagramPlugin
CSS
6
star
10

regio

Minimalist web framework with express-like aspirations
JavaScript
5
star
11

espruinofy

Browserify plugin for creating Espruino runnable bundles
JavaScript
3
star
12

GamepadButtons

Gamepad API polyfill for Cordova/PhoneGap on Android gamepads
Java
3
star
13

vscode-fsm-as-promised

Viewer for fsm-as-promised defined state machines
TypeScript
1
star
14

generator-kore

A browserify based workflow for knockout.js applications
JavaScript
1
star
15

vscode-supermodel-test

Makefile
1
star
16

writethelirycs

1
star
17

chai-as-typed

Chai assertions for types defined via JSDoc
JavaScript
1
star
18

regio-camera

Regio middleware for Tessel camera module
JavaScript
1
star
19

cordova-plugin-app-update

JavaScript
1
star
20

jquery-rest-observer

A simple jQuery plugin that adds REST observer support for ajax requests
JavaScript
1
star
21

cordova-keyguard-plugin

Cordova keyguard plugin
Java
1
star
22

express-rest-observer

REST observer for Express applications
JavaScript
1
star