title: facebook sdk: share local picture with text is driving me crazy
body: <p><strong>GOAL</strong></p>
  
  <p>In my camera app i want to let user share a picture with pre-formatted text and a description on the user's facebook wall.</p>
  
  <p><br>
  <strong>INTRO</strong></p>
  
  <p>I Googled a lot and followed "the terrific" <a href="https://developers.facebook.com/docs/android/getting-started/" rel="nofollow">facebook-getting-started</a>, trying many things, for !!days!!... no completely working solutions found yet.</p>
  
  <p>At least i think i got some points:</p>
  
  <ol>
  <li><p>The great Android Intent action_send works great but not choosing facebook, that works for text OR for pictures, not for both (!!), see <a href="https://developers.facebook.com/bugs/332619626816423" rel="nofollow">here</a></p></li>
  <li><p>applicationID, hashxxx, and everything else needed to link android app to facebook login, all things that i really don't understand and don't want to, done and at last working (thanx facebook for all this sh*t!!)</p></li>
  <li><p>share with facebook can be done (see <a href="https://developers.facebook.com/docs/android/share" rel="nofollow">here</a>):<br>
  3a. using the facebook app (installed in the device)<br>
  3b. using a login session (if facebook app is not installed)</p></li>
  <li><p>Facebook wants us to use its SDK, it's very [b|s]ad, but i can stand it.</p></li>
  <li><p>case 3a - facebook suggests us to use the shareDialog, and -fighting a lot with code snippets and samples suggested!- i have been able to do it, but i need it to work also if facebook app is not installed (case 3b.)</p></li>
  <li><p>case 3b - facebook suggests to use the "ugly" feedDialog as a fallback (see <a href="https://developers.facebook.com/docs/android/share#linkfeed" rel="nofollow">here</a>).<br>
  6a. feedDialog needs login and it's ok...<br>
  6b. it seems feedDialog cannot share local images, i really don't understand why... <a href="https://developers.facebook.com/docs/sharing/reference/feed-dialog/v2.0#params" rel="nofollow">here</a> facebook guide talks only about "URL" for the "picture" keyword...<br>
  5c. then i think i must use Request, i tried implementing it but nothing happened, i think i'm missing something... No useful references (=working examples) found.</p></li>
  </ol>
  
  <p><br>
  <strong>CODE SNIPPETS</strong> copy/paste/edit from SO and developers.facebook</p>
  
  <p>ShareDialog and session management in case facebook app is not installed <strong>IT'S WORKING</strong></p>
  
  <pre><code>/**
   * share image with facebook, using facebook sdk
   * @param pathToImage
   */
  private void shareWithFacebook(String pathToImage) {
      Log.i("SHARE", "share with facebook");
      if (FacebookDialog.canPresentShareDialog(getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
          // Publish the post using the Share Dialog
          Log.i("SHARE", "share with ShareDialog");
          FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
          .setCaption("Sharing photo taken with MyApp.")
          .setName("Snail Camera Photo")
          .setPicture("file://"+pathToImage)
          .setLink("http://myapplink")
          .setDescription("Image taken with MyApp for Android")
          .build();
          uiHelper.trackPendingDialogCall(shareDialog.present());
      } else {
          // maybe no facebook app installed, trying an alternative
          // here i think i need a session
          if (Session.getActiveSession() != null &amp;&amp; Session.getActiveSession().isOpened()) {
              publishFeedDialog(pathToImage);
          } else {
              Session session = Session.getActiveSession();
              if (!session.isOpened() &amp;&amp; !session.isClosed()) {
  
                  List&lt;String&gt; permissions = new ArrayList&lt;String&gt;();
                  permissions.add("publish_actions");
  
                  session.openForRead(new Session.OpenRequest(this)
                      .setPermissions(permissions)
                      .setCallback(mFacebookCallback));
              } else {
                  Session.openActiveSession(this, true, mFacebookCallback);
              }
          }
      }
  }
  
  private Session.StatusCallback mFacebookCallback = new Session.StatusCallback() {
      public void call(final Session session, final SessionState state, final Exception exception) {
          if (state.isOpened()) {
              String facebookToken = session.getAccessToken();
              Log.i("SHARE", facebookToken);
              Request.newMeRequest(session, new Request.GraphUserCallback() {
                  public void onCompleted(GraphUser user, com.facebook.Response response) {
                      publishFeedDialog(MP.LAST_TAKEN_FOR_GALLERY);
                  }
              }).executeAsync();
          }
      }
  };
  </code></pre>
  
  <p><br><br>
  feedDialog snippet, <strong>works for text fields, links, and remote url, but DOESN'T WORK FOR LOCAL PICTURES</strong> using "file://..." nor "file:///...". Error message: <code>picture URL is not properly formatted</code>.</p>
  
  <pre><code>private void publishFeedDialog(String pathToImage) {
      Bundle params = new Bundle();
      params.putString("name", "myapp Photo");
      params.putString("caption", "Sharing photo taken with myapp.");
      params.putString("description", "Image taken with myapp for Android");
      params.putString("link", "http://myapp.at.playstore");
      params.putString("picture", "file://"+pathToImage);
  
  
      WebDialog feedDialog = (
          new WebDialog.FeedDialogBuilder(EnhancedCameraPreviewActivity.this,//getApplicationContext(),
              Session.getActiveSession(),
              params))
          .setOnCompleteListener(new OnCompleteListener() {
  
              public void onComplete(Bundle values,
                  FacebookException error) {
                  Log.i("SHARE", "feedDialog.onComplete");
                  if (error == null) {
                      // story is posted
                      final String postId = values.getString("post_id");
                      if (postId != null) {
                          Toast.makeText(getApplicationContext(),
                              "Posted story, id: "+postId,
                              Toast.LENGTH_SHORT).show();
                      } else {
                          // User clicked the Cancel button
                          Toast.makeText(getApplicationContext(), 
                              "Publish cancelled", 
                              Toast.LENGTH_SHORT).show();
                      }
                  } else if (error instanceof FacebookOperationCanceledException) {
                      // User clicked the "x" button
                      Toast.makeText(getApplicationContext(), 
                          "Publish cancelled", 
                          Toast.LENGTH_SHORT).show();
                  } else {
                      // Generic, ex: network error
                      Toast.makeText(getApplicationContext(), 
                          "Error posting story", 
                          Toast.LENGTH_SHORT).show();
                  }
              }
  
          })
          .build();
      feedDialog.show();
  }
  </code></pre>
  
  <p><br><br>
  Another try, using <strong>Request</strong>, it says:</p>
  
  <blockquote>
    <p>photo upload problem. Error={HttpStatus: 403, errorCode: 200,
    errorType: OAuthException, errorMessage: (#200) Requires extended
    permission: publish_actions}</p>
  </blockquote>
  
  <p>I tried adding publish_actions permission in the session management above, maybe i miss something...</p>
  
  <pre><code>private void publishFeedDialog(String pathToImage) {
      Request request=Request.newPostOpenGraphObjectRequest(
              Session.getActiveSession(),
              "PhotoUpload",
              "myApp Photo Upload",
              "file://"+pathToImage,
              "http://myapp.at.playstore",
              "Image taken with myApp for Android",
              null,
              uploadPhotoRequestCallback);
      request.executeAsync();
  }
  </code></pre>
  
  <p><br><br>
  Last try with <strong>Request</strong>, absolutely nothing happens, both with or without "picture" keyword.</p>
  
  <pre><code>private void publishFeedDialog(String pathToImage) {
      Bundle parameters = new Bundle();
      parameters.putString("message", "Image taken with myApp for Android");
      parameters.putString("picture", "file://"+pathToImage);
      parameters.putString("caption", "myApp Photo");
  
      Request request = new Request(Session.getActiveSession(), "/me/feed", parameters, null);
      // also tried: Request request = new Request(Session.getActiveSession(), "/me/feed", parameters, com.facebook.HttpMethod.POST);
      request.executeAsync();
  }
  </code></pre>
  
  <p><br><br>
  <strong>QUESTIONS</strong></p>
  
  <p>-1- Are there some faults in my 1..6 points?</p>
  
  <p>-2- Can i share a local picture using FeedDialog?</p>
  
  <p>-3- if not, how to when facebook app is not installed?</p>
  
  <p>Thanks a lot!</p>