or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

analytics-monetization.mdcamera-media.mddevice-sensors.mddevice-system.mdindex.mdinput-hardware.mdlocation-maps.mdnetwork-communication.mdnotifications-ui.mdsecurity-auth.mdsocial-sharing.mdstorage-files.md
tile.json

social-sharing.mddocs/

0

# Social & Sharing

1

2

Social media integration, content sharing, and authentication for Facebook, Google+, Twitter platforms, and general content sharing capabilities.

3

4

## Capabilities

5

6

### Social Sharing

7

8

Share content across multiple platforms and applications with customizable options and platform-specific features.

9

10

```typescript { .api }

11

/**

12

* SocialSharing class for sharing content across platforms

13

*/

14

class SocialSharing {

15

/**

16

* Share content using device's native sharing dialog

17

* @param message Message to share (optional)

18

* @param subject Subject line (optional)

19

* @param file File path or array of file paths (optional)

20

* @param url URL to share (optional)

21

* @returns Promise indicating share completion

22

*/

23

static share(message?: string, subject?: string, file?: string | string[], url?: string): Promise<any>;

24

25

/**

26

* Share content via Twitter

27

* @param message Tweet text

28

* @param image Image URL or file path (optional)

29

* @param url URL to share (optional)

30

* @returns Promise indicating share completion

31

*/

32

static shareViaTwitter(message: string, image?: string, url?: string): Promise<any>;

33

34

/**

35

* Share content via Facebook

36

* @param message Message text

37

* @param image Image URL or file path (optional)

38

* @param url URL to share (optional)

39

* @returns Promise indicating share completion

40

*/

41

static shareViaFacebook(message: string, image?: string, url?: string): Promise<any>;

42

43

/**

44

* Share content via Facebook with paste message hint

45

* @param message Message text

46

* @param image Image URL or file path (optional)

47

* @param url URL to share (optional)

48

* @param pasteMessageHint Hint text for paste message

49

* @returns Promise indicating share completion

50

*/

51

static shareViaFacebookWithPasteMessageHint(message: string, image?: string, url?: string, pasteMessageHint: string): Promise<any>;

52

53

/**

54

* Share content via email

55

* @param message Email body

56

* @param subject Email subject

57

* @param to Array of recipient email addresses

58

* @param cc Array of CC email addresses (optional)

59

* @param bcc Array of BCC email addresses (optional)

60

* @param files Array of file attachments (optional)

61

* @returns Promise indicating share completion

62

*/

63

static shareViaEmail(message: string, subject: string, to: string[], cc?: string[], bcc?: string[], files?: string | string[]): Promise<any>;

64

65

/**

66

* Share content via SMS

67

* @param message SMS message text

68

* @param phonenumbers Comma-separated phone numbers

69

* @returns Promise indicating share completion

70

*/

71

static shareViaSMS(message: string, phonenumbers: string): Promise<any>;

72

73

/**

74

* Share content via WhatsApp

75

* @param message Message text

76

* @param image Image URL or file path (optional)

77

* @param url URL to share (optional)

78

* @returns Promise indicating share completion

79

*/

80

static shareViaWhatsApp(message: string, image?: string, url?: string): Promise<any>;

81

82

/**

83

* Share content via Instagram

84

* @param message Caption text

85

* @param image Image file path (required)

86

* @returns Promise indicating share completion

87

*/

88

static shareViaInstagram(message: string, image: string): Promise<any>;

89

90

/**

91

* Check if sharing via specific app is available

92

* @param appName App identifier

93

* @param message Message to test (optional)

94

* @param subject Subject to test (optional)

95

* @param image Image to test (optional)

96

* @param url URL to test (optional)

97

* @returns Promise resolving to availability status

98

*/

99

static canShareVia(appName: string, message?: string, subject?: string, image?: string, url?: string): Promise<any>;

100

101

/**

102

* Check if email sharing is available

103

* @returns Promise resolving to email availability

104

*/

105

static canShareViaEmail(): Promise<any>;

106

}

107

```

108

109

**Usage Examples:**

110

111

```typescript

112

import { SocialSharing } from 'ionic-native';

113

114

// General sharing functionality

115

class ShareService {

116

117

// Share text content

118

async shareText(text: string, subject?: string) {

119

try {

120

await SocialSharing.share(text, subject);

121

console.log('Content shared successfully');

122

} catch (error) {

123

console.error('Share failed:', error);

124

throw error;

125

}

126

}

127

128

// Share image with text

129

async shareImage(imagePath: string, message?: string) {

130

try {

131

await SocialSharing.share(message, null, imagePath);

132

console.log('Image shared successfully');

133

} catch (error) {

134

console.error('Image share failed:', error);

135

throw error;

136

}

137

}

138

139

// Share URL

140

async shareUrl(url: string, message?: string, subject?: string) {

141

try {

142

await SocialSharing.share(message, subject, null, url);

143

console.log('URL shared successfully');

144

} catch (error) {

145

console.error('URL share failed:', error);

146

throw error;

147

}

148

}

149

150

// Share multiple files

151

async shareFiles(files: string[], message?: string) {

152

try {

153

await SocialSharing.share(message, null, files);

154

console.log('Files shared successfully');

155

} catch (error) {

156

console.error('File share failed:', error);

157

throw error;

158

}

159

}

160

}

161

162

// Platform-specific sharing

163

class PlatformSharing {

164

165

// Share on Twitter

166

async shareOnTwitter(message: string, imageUrl?: string, linkUrl?: string) {

167

try {

168

// Check if Twitter is available

169

const canShare = await SocialSharing.canShareVia('twitter', message);

170

171

if (canShare) {

172

await SocialSharing.shareViaTwitter(message, imageUrl, linkUrl);

173

console.log('Shared on Twitter');

174

} else {

175

throw new Error('Twitter app not available');

176

}

177

} catch (error) {

178

console.error('Twitter share failed:', error);

179

// Fallback to web share

180

this.shareViaWebTwitter(message, linkUrl);

181

}

182

}

183

184

// Share on Facebook

185

async shareOnFacebook(message: string, imageUrl?: string, linkUrl?: string) {

186

try {

187

const canShare = await SocialSharing.canShareVia('facebook', message);

188

189

if (canShare) {

190

await SocialSharing.shareViaFacebook(message, imageUrl, linkUrl);

191

console.log('Shared on Facebook');

192

} else {

193

throw new Error('Facebook app not available');

194

}

195

} catch (error) {

196

console.error('Facebook share failed:', error);

197

// Fallback to web share

198

this.shareViaWebFacebook(message, linkUrl);

199

}

200

}

201

202

// Share via WhatsApp

203

async shareOnWhatsApp(message: string, imageUrl?: string, linkUrl?: string) {

204

try {

205

const canShare = await SocialSharing.canShareVia('whatsapp', message);

206

207

if (canShare) {

208

await SocialSharing.shareViaWhatsApp(message, imageUrl, linkUrl);

209

console.log('Shared on WhatsApp');

210

} else {

211

throw new Error('WhatsApp not available');

212

}

213

} catch (error) {

214

console.error('WhatsApp share failed:', error);

215

throw error;

216

}

217

}

218

219

// Share on Instagram (image required)

220

async shareOnInstagram(caption: string, imagePath: string) {

221

try {

222

const canShare = await SocialSharing.canShareVia('instagram');

223

224

if (canShare) {

225

await SocialSharing.shareViaInstagram(caption, imagePath);

226

console.log('Shared on Instagram');

227

} else {

228

throw new Error('Instagram not available');

229

}

230

} catch (error) {

231

console.error('Instagram share failed:', error);

232

throw error;

233

}

234

}

235

236

// Email sharing

237

async shareViaEmail(options: {

238

subject: string;

239

message: string;

240

to: string[];

241

cc?: string[];

242

bcc?: string[];

243

attachments?: string[];

244

}) {

245

try {

246

const canEmail = await SocialSharing.canShareViaEmail();

247

248

if (canEmail) {

249

await SocialSharing.shareViaEmail(

250

options.message,

251

options.subject,

252

options.to,

253

options.cc,

254

options.bcc,

255

options.attachments

256

);

257

console.log('Email sent successfully');

258

} else {

259

throw new Error('Email not available');

260

}

261

} catch (error) {

262

console.error('Email share failed:', error);

263

throw error;

264

}

265

}

266

267

// SMS sharing

268

async shareViaSMS(message: string, phoneNumbers: string[]) {

269

try {

270

const phones = phoneNumbers.join(',');

271

await SocialSharing.shareViaSMS(message, phones);

272

console.log('SMS shared successfully');

273

} catch (error) {

274

console.error('SMS share failed:', error);

275

throw error;

276

}

277

}

278

279

// Web fallback methods

280

private shareViaWebTwitter(text: string, url?: string) {

281

const twitterUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}${url ? '&url=' + encodeURIComponent(url) : ''}`;

282

window.open(twitterUrl, '_blank');

283

}

284

285

private shareViaWebFacebook(text: string, url?: string) {

286

const facebookUrl = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url || window.location.href)}&quote=${encodeURIComponent(text)}`;

287

window.open(facebookUrl, '_blank');

288

}

289

}

290

291

// Content sharing with analytics

292

class AnalyticsShareService extends PlatformSharing {

293

294

async shareWithAnalytics(content: {

295

type: 'text' | 'image' | 'url' | 'file';

296

data: any;

297

platform?: string;

298

title?: string;

299

}) {

300

const shareEvent = {

301

contentType: content.type,

302

platform: content.platform || 'native',

303

timestamp: new Date().toISOString(),

304

title: content.title

305

};

306

307

try {

308

// Track share attempt

309

this.trackEvent('share_attempted', shareEvent);

310

311

// Perform share based on type

312

switch (content.type) {

313

case 'text':

314

await this.shareText(content.data, content.title);

315

break;

316

case 'image':

317

await this.shareImage(content.data, content.title);

318

break;

319

case 'url':

320

await this.shareUrl(content.data, content.title);

321

break;

322

case 'file':

323

await this.shareFiles(Array.isArray(content.data) ? content.data : [content.data]);

324

break;

325

}

326

327

// Track successful share

328

this.trackEvent('share_completed', shareEvent);

329

330

} catch (error) {

331

// Track failed share

332

this.trackEvent('share_failed', { ...shareEvent, error: error.message });

333

throw error;

334

}

335

}

336

337

private trackEvent(eventName: string, data: any) {

338

// Implement analytics tracking

339

console.log(`Analytics: ${eventName}`, data);

340

}

341

}

342

```

343

344

### Facebook Integration

345

346

Comprehensive Facebook SDK integration for authentication, API access, and social features.

347

348

```typescript { .api }

349

/**

350

* Facebook login response

351

*/

352

interface FacebookLoginResponse {

353

/** Login status (connected, not_authorized, unknown) */

354

status: string;

355

/** Authentication response data */

356

authResponse: {

357

/** User ID */

358

userID: string;

359

/** Access token */

360

accessToken: string;

361

/** Session data */

362

session_key?: boolean;

363

/** Expiration timestamp */

364

expiresIn?: string;

365

/** Signed request */

366

sig?: string;

367

};

368

}

369

370

/**

371

* Facebook class for social authentication and API access

372

*/

373

class Facebook {

374

/**

375

* Login to Facebook

376

* @param permissions Array of permission strings

377

* @returns Promise resolving to FacebookLoginResponse

378

*/

379

static login(permissions: string[]): Promise<FacebookLoginResponse>;

380

381

/**

382

* Logout from Facebook

383

* @returns Promise indicating logout completion

384

*/

385

static logout(): Promise<any>;

386

387

/**

388

* Get current login status

389

* @returns Promise resolving to FacebookLoginResponse

390

*/

391

static getLoginStatus(): Promise<FacebookLoginResponse>;

392

393

/**

394

* Get current access token

395

* @returns Promise resolving to access token string

396

*/

397

static getAccessToken(): Promise<string>;

398

399

/**

400

* Show Facebook dialog

401

* @param options Dialog configuration options

402

* @returns Promise resolving to dialog result

403

*/

404

static showDialog(options: any): Promise<any>;

405

406

/**

407

* Make Facebook API request

408

* @param requestPath API endpoint path

409

* @param permissions Required permissions (optional)

410

* @returns Promise resolving to API response

411

*/

412

static api(requestPath: string, permissions?: string[]): Promise<any>;

413

414

/**

415

* Log Facebook Analytics event

416

* @param name Event name

417

* @param params Event parameters (optional)

418

* @param valueToSum Numeric value to sum (optional)

419

* @returns Promise indicating logging completion

420

*/

421

static logEvent(name: string, params?: Object, valueToSum?: number): Promise<any>;

422

423

/**

424

* Log purchase event

425

* @param value Purchase value

426

* @param currency Currency code

427

* @returns Promise indicating logging completion

428

*/

429

static logPurchase(value: number, currency: string): Promise<any>;

430

431

/**

432

* Send app invite

433

* @param options Invite configuration options

434

* @returns Promise resolving to invite result

435

*/

436

static appInvite(options: any): Promise<any>;

437

}

438

```

439

440

**Usage Examples:**

441

442

```typescript

443

import { Facebook, FacebookLoginResponse } from 'ionic-native';

444

445

// Facebook authentication service

446

class FacebookAuthService {

447

private currentUser: any = null;

448

private accessToken: string = '';

449

450

async login(requestedPermissions: string[] = ['public_profile', 'email']) {

451

try {

452

const response = await Facebook.login(requestedPermissions);

453

454

if (response.status === 'connected') {

455

this.accessToken = response.authResponse.accessToken;

456

this.currentUser = await this.getUserProfile();

457

458

console.log('Facebook login successful:', this.currentUser);

459

return {

460

success: true,

461

user: this.currentUser,

462

token: this.accessToken

463

};

464

} else {

465

throw new Error('Facebook login failed');

466

}

467

} catch (error) {

468

console.error('Facebook login error:', error);

469

throw error;

470

}

471

}

472

473

async logout() {

474

try {

475

await Facebook.logout();

476

this.currentUser = null;

477

this.accessToken = '';

478

console.log('Facebook logout successful');

479

} catch (error) {

480

console.error('Facebook logout error:', error);

481

throw error;

482

}

483

}

484

485

async getLoginStatus() {

486

try {

487

const response = await Facebook.getLoginStatus();

488

return response.status === 'connected';

489

} catch (error) {

490

console.error('Facebook status check error:', error);

491

return false;

492

}

493

}

494

495

async getUserProfile() {

496

try {

497

const profile = await Facebook.api('/me?fields=id,name,email,picture');

498

return profile;

499

} catch (error) {

500

console.error('Facebook profile error:', error);

501

throw error;

502

}

503

}

504

505

async getFriends() {

506

try {

507

const friends = await Facebook.api('/me/friends');

508

return friends.data;

509

} catch (error) {

510

console.error('Facebook friends error:', error);

511

throw error;

512

}

513

}

514

515

async postToFeed(message: string, link?: string, picture?: string) {

516

try {

517

const postData: any = { message };

518

519

if (link) postData.link = link;

520

if (picture) postData.picture = picture;

521

522

const result = await Facebook.api('/me/feed', ['publish_actions']);

523

return result;

524

} catch (error) {

525

console.error('Facebook post error:', error);

526

throw error;

527

}

528

}

529

530

getCurrentUser() {

531

return this.currentUser;

532

}

533

534

getAccessToken() {

535

return this.accessToken;

536

}

537

}

538

539

// Facebook sharing and engagement

540

class FacebookEngagement {

541

542

async shareLink(options: {

543

href: string;

544

description?: string;

545

hashtag?: string;

546

}) {

547

try {

548

const dialogOptions = {

549

method: 'share',

550

href: options.href,

551

description: options.description,

552

hashtag: options.hashtag

553

};

554

555

const result = await Facebook.showDialog(dialogOptions);

556

console.log('Facebook link shared:', result);

557

return result;

558

} catch (error) {

559

console.error('Facebook share error:', error);

560

throw error;

561

}

562

}

563

564

async inviteFriends(appId: string, message?: string) {

565

try {

566

const inviteOptions = {

567

url: `https://fb.me/${appId}`,

568

picture: 'https://your-app.com/invite-image.png',

569

message: message || 'Check out this awesome app!'

570

};

571

572

const result = await Facebook.appInvite(inviteOptions);

573

console.log('Facebook invites sent:', result);

574

return result;

575

} catch (error) {

576

console.error('Facebook invite error:', error);

577

throw error;

578

}

579

}

580

581

// Analytics integration

582

async trackEvent(eventName: string, parameters?: any, value?: number) {

583

try {

584

await Facebook.logEvent(eventName, parameters, value);

585

console.log('Facebook event tracked:', eventName);

586

} catch (error) {

587

console.error('Facebook analytics error:', error);

588

}

589

}

590

591

async trackPurchase(amount: number, currency: string = 'USD') {

592

try {

593

await Facebook.logPurchase(amount, currency);

594

console.log('Facebook purchase tracked:', amount, currency);

595

} catch (error) {

596

console.error('Facebook purchase tracking error:', error);

597

}

598

}

599

}

600

```

601

602

### Google+ Integration

603

604

Google+ authentication and social features integration.

605

606

```typescript { .api }

607

/**

608

* GooglePlus class for Google+ authentication

609

*/

610

class GooglePlus {

611

/**

612

* Login to Google+

613

* @param options Login configuration options

614

* @returns Promise resolving to user profile data

615

*/

616

static login(options: any): Promise<any>;

617

618

/**

619

* Try silent login (using existing credentials)

620

* @param options Login configuration options

621

* @returns Promise resolving to user profile data

622

*/

623

static trySilentLogin(options: any): Promise<any>;

624

625

/**

626

* Logout from Google+

627

* @returns Promise indicating logout completion

628

*/

629

static logout(): Promise<any>;

630

631

/**

632

* Disconnect from Google+

633

* @returns Promise indicating disconnection completion

634

*/

635

static disconnect(): Promise<any>;

636

637

/**

638

* Check if Google+ services are available

639

* @returns Promise resolving to availability status

640

*/

641

static isAvailable(): Promise<boolean>;

642

}

643

```

644

645

**Usage Examples:**

646

647

```typescript

648

import { GooglePlus } from 'ionic-native';

649

650

// Google+ authentication service

651

class GooglePlusAuthService {

652

653

async login() {

654

try {

655

const isAvailable = await GooglePlus.isAvailable();

656

if (!isAvailable) {

657

throw new Error('Google+ services not available');

658

}

659

660

const options = {

661

scopes: 'profile email',

662

webClientId: 'your-web-client-id.apps.googleusercontent.com'

663

};

664

665

const user = await GooglePlus.login(options);

666

console.log('Google+ login successful:', user);

667

668

return {

669

success: true,

670

user: {

671

id: user.userId,

672

name: user.displayName,

673

email: user.email,

674

image: user.imageUrl,

675

idToken: user.idToken,

676

accessToken: user.accessToken

677

}

678

};

679

} catch (error) {

680

console.error('Google+ login error:', error);

681

throw error;

682

}

683

}

684

685

async silentLogin() {

686

try {

687

const options = {

688

scopes: 'profile email',

689

webClientId: 'your-web-client-id.apps.googleusercontent.com'

690

};

691

692

const user = await GooglePlus.trySilentLogin(options);

693

console.log('Google+ silent login successful:', user);

694

return user;

695

} catch (error) {

696

console.log('Google+ silent login failed:', error);

697

return null;

698

}

699

}

700

701

async logout() {

702

try {

703

await GooglePlus.logout();

704

console.log('Google+ logout successful');

705

} catch (error) {

706

console.error('Google+ logout error:', error);

707

throw error;

708

}

709

}

710

711

async disconnect() {

712

try {

713

await GooglePlus.disconnect();

714

console.log('Google+ disconnect successful');

715

} catch (error) {

716

console.error('Google+ disconnect error:', error);

717

throw error;

718

}

719

}

720

}

721

```

722

723

### Twitter Integration

724

725

Twitter authentication and interaction capabilities.

726

727

```typescript { .api }

728

/**

729

* TwitterConnect class for Twitter authentication

730

*/

731

class TwitterConnect {

732

/**

733

* Login to Twitter

734

* @returns Promise resolving to user credentials

735

*/

736

static login(): Promise<any>;

737

738

/**

739

* Logout from Twitter

740

* @returns Promise indicating logout completion

741

*/

742

static logout(): Promise<any>;

743

744

/**

745

* Show user profile

746

* @param userid User ID to display

747

* @returns Promise resolving to user data

748

*/

749

static showUser(userid: string): Promise<any>;

750

}

751

```

752

753

**Usage Examples:**

754

755

```typescript

756

import { TwitterConnect } from 'ionic-native';

757

758

// Twitter authentication service

759

class TwitterAuthService {

760

761

async login() {

762

try {

763

const response = await TwitterConnect.login();

764

765

console.log('Twitter login successful:', response);

766

767

return {

768

success: true,

769

user: {

770

id: response.userId,

771

username: response.userName,

772

token: response.token,

773

secret: response.secret

774

}

775

};

776

} catch (error) {

777

console.error('Twitter login error:', error);

778

throw error;

779

}

780

}

781

782

async logout() {

783

try {

784

await TwitterConnect.logout();

785

console.log('Twitter logout successful');

786

} catch (error) {

787

console.error('Twitter logout error:', error);

788

throw error;

789

}

790

}

791

792

async showUserProfile(userId: string) {

793

try {

794

const user = await TwitterConnect.showUser(userId);

795

console.log('Twitter user profile:', user);

796

return user;

797

} catch (error) {

798

console.error('Twitter profile error:', error);

799

throw error;

800

}

801

}

802

}

803

```

804

805

### Social Authentication Manager

806

807

Unified service for managing multiple social authentication providers.

808

809

```typescript

810

// Unified social authentication service

811

class SocialAuthManager {

812

private providers: Map<string, any> = new Map();

813

814

constructor() {

815

// Initialize available providers

816

this.providers.set('facebook', new FacebookAuthService());

817

this.providers.set('google', new GooglePlusAuthService());

818

this.providers.set('twitter', new TwitterAuthService());

819

}

820

821

async login(provider: string, options?: any) {

822

const authService = this.providers.get(provider);

823

if (!authService) {

824

throw new Error(`Provider ${provider} not supported`);

825

}

826

827

try {

828

const result = await authService.login(options);

829

830

// Store authentication info

831

this.storeAuthInfo(provider, result);

832

833

return result;

834

} catch (error) {

835

console.error(`${provider} login failed:`, error);

836

throw error;

837

}

838

}

839

840

async logout(provider: string) {

841

const authService = this.providers.get(provider);

842

if (!authService) {

843

throw new Error(`Provider ${provider} not supported`);

844

}

845

846

try {

847

await authService.logout();

848

this.clearAuthInfo(provider);

849

} catch (error) {

850

console.error(`${provider} logout failed:`, error);

851

throw error;

852

}

853

}

854

855

async logoutAll() {

856

const logoutPromises = Array.from(this.providers.keys()).map(provider =>

857

this.logout(provider).catch(error =>

858

console.error(`Failed to logout from ${provider}:`, error)

859

)

860

);

861

862

await Promise.all(logoutPromises);

863

}

864

865

isLoggedIn(provider: string): boolean {

866

const authInfo = localStorage.getItem(`${provider}_auth`);

867

return !!authInfo;

868

}

869

870

getAuthInfo(provider: string): any {

871

const authInfo = localStorage.getItem(`${provider}_auth`);

872

return authInfo ? JSON.parse(authInfo) : null;

873

}

874

875

private storeAuthInfo(provider: string, authInfo: any) {

876

localStorage.setItem(`${provider}_auth`, JSON.stringify(authInfo));

877

}

878

879

private clearAuthInfo(provider: string) {

880

localStorage.removeItem(`${provider}_auth`);

881

}

882

883

getSupportedProviders(): string[] {

884

return Array.from(this.providers.keys());

885

}

886

}

887

888

// Usage example

889

const socialAuth = new SocialAuthManager();

890

891

// Login with different providers

892

async function loginWithProvider(provider: 'facebook' | 'google' | 'twitter') {

893

try {

894

const result = await socialAuth.login(provider);

895

console.log(`Logged in with ${provider}:`, result.user);

896

} catch (error) {

897

console.error(`Failed to login with ${provider}:`, error);

898

}

899

}

900

901

// Check login status

902

function checkAuthStatus() {

903

const providers = socialAuth.getSupportedProviders();

904

905

providers.forEach(provider => {

906

if (socialAuth.isLoggedIn(provider)) {

907

const authInfo = socialAuth.getAuthInfo(provider);

908

console.log(`Authenticated with ${provider}:`, authInfo.user);

909

}

910

});

911

}

912

```