分享到Instagram并获得回拨

问题描述:

我必须将我的应用程序中的图像分享到instagram。我已经通过Instagram开发者文档,他们只提及通过Intent方法共享,但我需要的是我必须在发布成功后得到回调。分享到Instagram并获得回拨

private void createInstagramIntent(String type, String mediaPath){ 

    // Create the new Intent using the 'Send' action. 
    Intent share = new Intent(Intent.ACTION_SEND); 

    // Set the MIME type 
    share.setType(type); 

    // Create the URI from the media 
    File media = new File(mediaPath); 
    Uri uri = Uri.fromFile(media); 

    // Add the URI to the Intent. 
    share.putExtra(Intent.EXTRA_STREAM, uri); 

    // Broadcast the Intent. 
    startActivity(Intent.createChooser(share, "Share to")); 
} 

有没有办法做到这一点?

+0

@rekire ofcourse将得到一个回调startActivityForResult。但我们不能确定用户是否共享。如果你按回退也startActivityForResult将被称为 – droidev

+1

他们的API是安静的基本:https://instagram.com/developer/mobile-sharing/android-intents/没有更多的信息提供。 – rekire

+0

那么如果我没有在手机上安装Instagram,该怎么办? – droidev

根据他们的API有几个选项。起初是指他们的Android Intents,这是一个不好的例子恕我直言,这或多或少是Android中如何共享数据的默认方式。你想要什么更像是打开他们的应用程序。对于这样的情况是存在的setPackage()选项:

// Create the new Intent using the 'Send' action. 
Intent share = new Intent(Intent.ACTION_SEND); 

// Limit this call to instagram 
share.setPackage("com.instagram.android"); 

// Set the MIME type 
share.setType(type); 

// Create the URI from the media 
File media = new File(mediaPath); 
Uri uri = Uri.fromFile(media); 

// Add the URI to the Intent. 
share.putExtra(Intent.EXTRA_STREAM, uri); 

try { 
    // Fire the Intent. 
    startActivityForResult(share, REQUEST_CODE); 
} catch(ActivityNotFoundException e) { 
    // instagram not installed 
} 

现在对于Instagram的未安装你几乎丢失的情况。如果没有其他的SDK,你就无能为力。

一个非常复杂的解决方法可能是将文件上传到您自己的后端。然后打开浏览器访问oauth标记以通过后端上传图像。然而,这是一个安静的昂贵的解决方案,我会避免。