Github link: https://github.com/Sudarshan101/instagramShare

thank you

Share post on Instagram using ionic and Cordova plugin 

Create a project run this command:

ionic start  blank 

then move into the newly created directory:

cd 

Install the required plugin and NPM packages

ionic cordova plugin add cordova-plugin-camera
ionic cordova plugin add cordova-plugin-x-socialsharing
npm install --save @ionic-native/camera
?npm install --save @ionic-native/social-sharing

Open app.js in src ->app-> app.module.ts and add the module of ts file

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { SocialSharing } from '@ionic-native/social-sharing';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { Camera } from '@ionic-native/camera';
@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    SocialSharing,
    Camera,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

Open home.html in src ->pages-> home->home.html and add code


   
       
         Insta share 
       
    


   Load ImageShare

 

Open home.html in src ->pages-> home->home.ts and add code

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { SocialSharing } from '@ionic-native/social-sharing';
import { Camera } from '@ionic-native/camera';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {
currentImage = null;
  constructor(public navCtrl: NavController, public socialSharing: SocialSharing, private camera: Camera) {
  }
  loadImage() {
    const options: CameraOptions = {
      quality: 100,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY      
    }
    this.camera.getPicture(options).then(data => {
     this.currentImage = 'data:image/jpeg;base64,' + data;
     }, err => {
      // Handle error
      console.log(err)
     });
  }
  share(){
      this.socialSharing.shareViaInstagram('Share instagram', this.currentImage).then(() => {  // Success!}).catch(() => {  // Error!}); }}

After add platform in your application code platform add command: 

ionic cordova platform add android/ios/windows

Build and Run command

ionic cordova build android/ios/windows
ionic cordova run android/ios/windows

Github link: https://github.com/Sudarshan101/instagramShare

thank you

About the author
Code solution

info@codesolution.co.in

Discussion
  • 0 comments

Add comment To Login
Add comment