2017-03-09 75 views
0

美好的一天!Facebook API - 分享活動

我目前正在開發一個安全應用程序,一旦激活,將自動獲取GPS,通過短信發送,拍照,然後通過Facebook分享。我能夠做一個簡單的共享活動,但我無法自動執行Facebook共享,而無法顯示該帖子的預覽。發佈的內容將由用戶輸入,因此不會違反Facebook API規定。我知道這是可能的,因爲一些手機遊戲執行它們。任何形式的幫助將非常感激!

回答

0

我已經實現了它的一些天回這樣.....

imageview_fbshare.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      if(Util.isDeviceOnline(MainActivity.this)) { 
       Util.showProDialog(MainActivity.this,"Please wait...."); 

      LoginManager.getInstance().logInWithPublishPermissions(
        MainActivity.this, 
        Arrays.asList("publish_actions")); 
       ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
       lastimage.compress(Bitmap.CompressFormat.PNG, 100, stream); 
       byte[] byteArray = stream.toByteArray(); 
       Bundle params = new Bundle(); 
       // params.putString("caption", etxt_status.getText().toString()); 
       //params.putString("place", user_loc_id); 
       //params.putString("tags", ids); 
       params.putByteArray("picture", byteArray); 

       new GraphRequest(
         AccessToken.getCurrentAccessToken(), 
         "/" + user_id + "/photos", 
         params, 
         HttpMethod.POST, 
         new GraphRequest.Callback() { 
          public void onCompleted(GraphResponse response) { 
           //new getPlaceId().execute(); 
           JSONObject o = response.getJSONObject(); 
           try { 
            String user_status_id = o.getString("id"); 

           } catch (Exception ex) { 

           } 

           Util.dimissProDialog(); 


          } 
         } 
       ).executeAsync(); 
      } 
      else { 
       Toast.makeText(MainActivity.this,"OOps! Network Connection Error",Toast.LENGTH_LONG).show(); 
      } 
     } 
    }); 
+0

線imageview_fbshare不能得到解決。我似乎無法使這項工作 –

+0

它只是簡單的imageview點擊我在facebook上分享圖像,你可以簡單地把這個裏面的按鈕等onclick –

+0

是Facebook的API的Util.isDeviceOnline的一部分?似乎不能解決它。 –