2014-02-08 56 views
2

我有一個應用程序,我想在Facebook上分享歷史記錄。我的應用程序沒有網絡。我只想分享帶有標題和說明的圖片,如果可以點擊共享網站,他們會重定向到谷歌播放下載應用程序或Facebook應用程序頁面。只有在設置了opengraphobject.setproperty(「og:url」)時,Facebook SDK才能生成用戶預覽

我在大多數的facebook樣本中尋找答案,這裏和那裏有一些我確實做錯了的事情。 我做了所有的Facebook應用程序配置。關鍵哈希值等......我在名爲Publicar a Lugar的開放圖中創建一個歷史記錄。 Action =「Publicar」Object =「Lugar」。

我有這個代碼

private void OpenShareDialog(){ 
    Session session = Session.getActiveSession(); 

    if (session != null) { 
     // Check for publish permissions 
     List<String> permissions = session.getPermissions(); 
     if (!isSubsetOf(PERMISSIONS, permissions)) { 
      pendingPublishReauthorization = true; 
      Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS); 
      session.requestNewPublishPermissions(newPermissionsRequest); 
      return; 
     } 

    } 

    OpenGraphObject oplugar = OpenGraphObject.Factory.createForPost("namespace:lugar"); 
    oplugar.setProperty("og:type","namespace:lugar"); 
    oplugar.setProperty("og:title", LugarCargado.getNombre()); 
    //oplugar.setProperty("og:image", "http://estaticos.sport.es/resources/jpg/2/1/1391546433412.jpg"); 
    //oplugar.setProperty("og:url", "http://www.udg.edu/"); 
    oplugar.setProperty("og:description", LugarCargado.getDescripcion()); 

    //Bitmap bitmap;  
    //List<Bitmap> bitmaps = new ArrayList<Bitmap>(); 
    //bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.icoappfacebook2); 
    //Log.i(TAG, "Imagen: Height:"+bitmap.getHeight()+ " Width:"+ bitmap.getWidth()); 
    //bitmaps.add(bitmap); 

    //OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class); 
    OpenGraphAction action = OpenGraphAction.Factory.createForPost("namespace:publicar"); 
    action.setProperty("lugar", oplugar); 
    action.setType("namespace:publicar"); 
    action.setProperty("previewPropertyName", oplugar); 

    FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "lugar") 
      //.setImageAttachmentsForObject("lugar", bitmaps, true) 
      //.setImageAttachmentsForAction(bitmaps,true); 
      .build(); 

    uiHelper.trackPendingDialogCall(shareDialog.present()); 
} 

我在智能手機2個diferent錯誤調試:

1 - 如果我取消此行的一個

//oplugar.setProperty("og:image", "http://estaticos.sport.es/resources/jpg/2/1/1391546433412.jpg"); 
//oplugar.setProperty("og:url", "http://www.udg.edu/"); 

我有一個錯誤說「com.facebook.FacebookException:無法爲用戶生成預覽」。我不能推一個網址

2-如果我想添加一個自定義圖像。如果我取消這個代碼

//Bitmap bitmap;  
    //List<Bitmap> bitmaps = new ArrayList<Bitmap>(); 
    //bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.icoappfacebook2); 
    //Log.i(TAG, "Imagen: Height:"+bitmap.getHeight()+ " Width:"+ bitmap.getWidth()); 
    //bitmaps.add(bitmap); 

//.setImageAttachmentsForAction(bitmaps,true); 

我有一個黑色的窗口,有些事情似乎重新啓動...

02-08 15:09:46.500:W/GAV3(15911):線程[GAThread,5,main]:服務不可用(代碼= 1), 將重試。 02-08 15:09:46.500:I/GAV3(15911):線程[GAThread,5,main]:沒有 找到活動數據。 02-08 15:09:48.482:D/AbsListView(15911): unregisterIRListener()被調用02-08 15:09:48.982: D/AbsListView(15911):onVisibilityChanged()被調用,可見性:4 02 -08 15:09:48.982:D/AbsListView(15911):unregisterIRListener()是 調用02-08 15:09:51.525:W/GAV3(15911):線程[服務 重新連接,5,主要]:服務不可用(代碼= 1),使用本地商店。 02-08 15:09:53.778:D/AbsListView(16092):Get MotionRecognitionManager 02-08 15:09:53.778:D/AbsListView(16092):onVisibilityChanged()爲 調用,visibility:8 02-08 15 :09/53.778:D/AbsListView(16092): unregisterIRListener()被稱爲02-08 15:09:53.788: D/ProgressBar(16092):setProgress = 0 02-08 15:09:53.788: D/ProgressBar(16092):setProgress = 0,fromUser = false 02-08 15:09:53.788:D/ProgressBar(16092):mProgress = 0mIndeterminate = false,mMin = 0,mMax = 10000 02-08 15:09: 53.828: D/AbsListView(16092):onVisibilityChanged()被調用,visibility:4 02-08 15:09:53.828:D/AbsListView(16092):unregisterIRListener()是 調用02-08 15:09 :53.838:D/AbsListView(16092): onVisibilityChanged()被調用,visibility:0 02-08 15:09:53.838: D/AbsListView(16092):unregisterIRListener()被調用02-08 15:09: 53.848:D/libEGL(16092):加載 /system/lib/egl/libEGL_adreno200.so 02-08 15:09:53.858: D/libEGL(16092):加載/system/lib/egl/libGLESv1_CM_adreno200.so 02-08 15:09:53。858:d/libEGL(16092):加載 /system/lib/egl/libGLESv2_adreno200.so 02-08 15:09:53.858: I /的Adreno200-EGL(16092):1.4 EGL QUALCOMM 構建:

AYELDER_AU_LINUX_ANDROID_JB_2.5.5.04.02.02.092.023 + PATCH [ES] _msm8960_JB_2.5.5_CL3556704_release_ENGG(CL3556704)02-08 15:09:53.858:I/Adreno200-EGL(16092):Build Date: 05/17/13 Fri 02-08 15:09:53.858:I/Adreno200-EGL(16092):本地分支: 02-08 15:09:53.858:I/Adreno200-EGL(16092):遠程分支: quic/jb_2.5.5 02 -08 15:09:53.858:I/Adreno200-EGL(16092):本地 修補程序:34c9e193f12610d3e68dabd6198d2c4bfbc66974 RB:更新 主人

時間戳hw_image的rb_texture_update_aliased 02-08 15:09:53.858:I /的Adreno200-EGL(16092):重構分公司: AU_LINUX_ANDROID_JB_2.5.5.04.02.02.092.023 + 01d3c78 +

e6f0547 + LOCAL_PATCH [ES] 02-08 15:09:53.878: D/OpenGLRenderer(16092):啓用調試模式0 02-08 15:09:53.878: D/ProgressBar(16092):updateDrawableBounds:left = 0 02-08 15:09:53.878:D/ProgressBar(16092):updateDrawableBounds:top = 0 02-08 15:09:53.878:D/ProgressBar(16092):updateDrawableBounds:right = 72 02-08 15:09:53.878 :D/ProgressBar(16092):updateDrawableBounds:bottom = 72 02-08 15:09:54.058 :I/System(16092):已加載時區 en的名稱爲217ms(ICU中爲205ms)02-08 15:09:54.088: D/AbsListView(16092):onVisibilityChanged()被調用,visibility:0 02 -08 15:09:54.088:D/AbsListView(16092):unregisterIRListener()是 調用02-08 15:09:54.168:D/AbsListView(16092): unregisterIRListener()被調用02-08 15:09: 54.178: D/AbsListView(16092):unregisterIRListener()被調用02-08 15:09:54.188:E/ViewRootImpl(16092):sendUserActionEvent()mView == null 02-08 15:09:54.268:D/AbsListView(16092):unregisterIRListener() 被稱爲02-08 15:09:58.833:W/GAV3(16092):線程[GAThread,5,main]: 服務不可用(代碼= 1),將重試。 02-08 15:09:58.833: I/GAV3(16092):線程[GAThread,5,main]:找不到任何活動數據。 02-08 15:10:03.838:W/GAV3(16092):線程[Service Reconnect,5,main]:服務 不可用(代碼= 1),使用本地存儲。 02-08 15:10:10.565: d/AbsListView(16092):unregisterIRListener()被調用

並顯示過去的活動。

上面的代碼sharedialog顯示我的facebook對話框,我可以分享。但沒有鏈接,沒有我的形象。

你能幫助我嗎?我嘗試了很多不同的東西!

這是我的智能手機? facebook版本?

您是否有一個簡單的示例來在共享對話框中分享一個帶有描述的自定義(製作爲用戶)圖像?

感謝和抱歉我的英語。

回答

1

如果您沒有網絡組件,則不要在og對象中設置url。如果你設置了一個url,Facebook會嘗試去抓取這個url,如果從那裏抓取的OG元數據與你提供的不匹配,那麼它會失敗。

如果您想爲您的OG操作添加位圖,除了您目前正在執行的操作之外,您還必須將一個NativeAppCallContentProvider添加到清單中。在此處查看文檔:https://developers.facebook.com/docs/reference/android/current/class/NativeAppCallContentProvider/這就是Facebook應用程序實際可以獲取您要發送的位圖的方式。

最後,看看SDK附帶的Scrumptious示例應用程序。它有一個選項(如果你「跳過登錄」)創建一個新的OG對象,並附帶一個圖像附件。

+0

好的網址。但是我的清單中有NativeAppCallContentProvider。而我正在嘗試執行令人讚歎的示例,並且在必須進行預覽時失敗。並出現錯誤「無法爲用戶生成預覽」。這發生在不同的移動電話和我的代碼上。預覽顯示一秒鐘,然後消失顯示此消息。在示例中,我只選擇了一些我吃螞蟻而沒有登錄的圖片。 – jsalva

+0

您使用的是什麼版本的SDK和Facebook應用程序? –

+0

sdk 3.6和android的最後一次facebook更新。 – jsalva

0

有了這段代碼,它的工作原理,我沒有「無法生成預覽」。 但是這段代碼正在做一些與我想要的不同的東西。 此代碼打開一個OGActiondialog,但是當我分享它時,帖子永遠不會出現在提要中,並出現在活動註冊表中,但只顯示照片,而不是像「正常」共享鏈接的名稱或描述(左邊的小照片,titol和右側說明)。

可以做到這一點嗎?

private void OpenShareDialog2(){ 

    if (canPresentOGShareDialog) { 
     Session session = Session.getActiveSession(); 

     if (session != null) { 
      // Check for publish permissions 
      List<String> permissions = session.getPermissions(); 
      if (!isSubsetOf(PERMISSIONS, permissions)) { 
       pendingPublishReauthorization = true; 
       Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS); 
       session.requestNewPublishPermissions(newPermissionsRequest); 
       Log.d(TAG, "Permisos pedidos"); 
       return; 
      } 

     } 

     OpenGraphObject oplugar = OpenGraphObject.Factory.createForPost("namespace:lugar"); 
     oplugar.setProperty("og:type","namespace:lugar"); 
     oplugar.setProperty("og:title", LugarCargado.getNombre()); 
     oplugar.setProperty("og:description", LugarCargado.getDescripcion()); 



     //OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class); 
     OpenGraphAction action = OpenGraphAction.Factory.createForPost("namespace:publicar"); 
     action.setProperty("lugar", oplugar); 
     action.setType("namespace:publicar"); 
     //action.setProperty("previewPropertyName", "lugar"); 
     //action.setProperty("fb:explicitly_shared", true); 
     //action.setExplicitlyShared(true); 

     boolean userGenerated = false; 
     if (urifoto != null) { 
      String photoUriString = urifoto.toString(); 
      Pair<File, Integer> fileAndMinDimemsion = getImageFileAndMinDimension(); 
      userGenerated = fileAndMinDimemsion.second >= USER_GENERATED_MIN_SIZE; 

      // If we have a content: URI, we can just use that URI, otherwise we'll need to add it as an attachment. 
      if (fileAndMinDimemsion != null && urifoto.getScheme().startsWith("content")) { 
       action.setImage(getImageListForAction(photoUriString, userGenerated)); 
      } 
     } 

     FacebookDialog.OpenGraphActionDialogBuilder builder = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "lugar"); 
       //.setFragment(SelectionFragment.this); 

     if (urifoto != null && !urifoto.getScheme().startsWith("content")) { 
      builder.setImageAttachmentFilesForAction(Arrays.asList(new File(urifoto.getPath())), userGenerated); 
     } 

     uiHelper.trackPendingDialogCall(builder.build().present()); 
    } 
} 

private Pair<File, Integer> getImageFileAndMinDimension() { 
    File photoFile = null; 
    String photoUriString = urifoto.toString(); 
    if (photoUriString.startsWith("file://")) { 
     photoFile = new File(urifoto.getPath()); 
    } else if (photoUriString.startsWith("content://")) { 
     String [] filePath = { MediaStore.Images.Media.DATA }; 
     Cursor cursor = this.getContentResolver().query(urifoto, filePath, null, null, null); 
     if (cursor != null) { 
      cursor.moveToFirst(); 
      int columnIndex = cursor.getColumnIndex(filePath[0]); 
      String filename = cursor.getString(columnIndex); 
      cursor.close(); 

      photoFile = new File(filename); 
     } 
    } 

    if (photoFile != null) { 
     InputStream is = null; 
     try { 
      is = new FileInputStream(photoFile); 

      // We only want to get the bounds of the image, rather than load the whole thing. 
      BitmapFactory.Options options = new BitmapFactory.Options(); 
      options.inJustDecodeBounds = true; 
      BitmapFactory.decodeStream(is, null, options); 

      return new Pair<File, Integer>(photoFile, Math.min(options.outWidth, options.outHeight)); 
     } catch (Exception e) { 
      return null; 
     } finally { 
      Utility.closeQuietly(is); 
     } 
    } 
    return null; 
} 

我從它美味的樣本中或多或少得到它!

相關問題