簡體   English   中英

未安裝Facebook時如何在Android上使用ShareOpenGraphContent

[英]How to use ShareOpenGraphContent on Android when Facebook is not Installed

我正在使用ShareOpenGraphContent在我的Android應用程序中通過Facebook OpenGraph共享圖像,它僅在安裝Facebook時有效。

    SharePhoto photo = new SharePhoto.Builder()
            .setBitmap(bitmap)
            .setCaption("https://play.google.com/store/apps/details?id=" +
                    G.app.getPackageName())
            .build();

    // Create an object
    ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type", "my app:type")
            .putString("og:title", "my app title")
            .putString("og:url", "https://market.android.com/details?id=" + G.app.getPackageName())
            .putPhoto("og:image", photo)
            .build();

    // Create an action
    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("my app:object")
            .putObject("my object", object)
            .build();

    // Create the content
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("type")
            .setAction(action)
            .build();

    final ShareButton shareButton = (ShareButton) findViewById(R.id.facebookShare);
    shareButton.setShareContent(content);
    shareButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // do some thing
            bitmap.recycle();
        }
    });

G.app生命周期 api。

我了解我需要發布操作權限和Facebook批准,此打開的圖表才能在未安裝Facebook應用的情況下正常工作。 但是我該怎么做呢? 我想向用戶顯示與他們安裝Facebook應用程序時看到的對話框相同的對話框。

如果未安裝FB應用程序,則通常的后備狀態是Web對話框,但是Web對話框不支持位圖(僅圖像的URL),這可能就是為什么它不適合您的原因。

您需要將圖像切換為Web URL,或將ShareApi類與publish_actions權限一起使用(但在這種情況下,不會為您的用戶提供對話框)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM