title: Posting to Facebook with PHP/jQuery/Ajax
body: <p>Alright, there are a lot of moving parts here, so I will try to be as thorough as possible.</p>
  
  <p>To start, there is an  tag on my site, which is designated to post a dynamically loaded photo to facebook.</p>
  
  <pre><code>&lt;a onclick=\"postToFacebook('"+photoURL+"');\"&gt;&lt;img src='facebook-icon.png'/&gt;&lt;/a&gt;
  </code></pre>
  
  <p>The stripped down javascript function that is called when this link is clicked looks like this:</p>
  
  <pre><code>function postToFacebook(photoURL) {
      contentCode += "&lt;div id='overlay-col2'&gt;&lt;input type='text' id='facebook-caption-textbox' name='facebook-caption-textbox' class='textbox-wide inactive' value='Caption'/&gt;";
      contentCode += "&lt;textarea id='facebook-message-textarea' name='facebook-message-textarea' class='textarea-wide inactive'&gt;Say something about this photo...&lt;/textarea&gt;";
      contentCode += "&lt;a class='overlay-submit-btn' onclick=\"submitFacebookPosting('"+photoURL+"');\"&gt;Post to Facebook&lt;/a&gt;&lt;/div&gt;";
  
      $("#overlay-body-content").empty().html(contentCode);
  }
  </code></pre>
  
  <p>What this code does is creates populates an overlay window with a small web form that enables the user to enter in a caption for the photo, as well as a textarea to say a little something about the photo.  As you can see, when they hit the submit link, another javascript function is called: submitFacebookPosting().  That function looks like this:</p>
  
  <pre><code>function submitFacebookPosting(photoURL) {
      var photoCaption = $("#facebook-caption-textbox").attr("value");
      var photoMessage = $("#facebook-message-textarea").val();
  
      $.ajax({
          url: 'postToFacebook.php',
          type: 'POST',
          data: ({photoURL:photoURL, photoCaption:photoCaption, photoMessage:photoMessage}),
          success: function(data) {
              if (data == "success") {
                  alert("Photo has been posted to your Facebook Wall.");
              } else {
                  alert(data);
              }
          }
      });
  }
  </code></pre>
  
  <p>Finally, there is the file, postToFacebook.php, which is considerably longer.  The contents of that look like this:</p>
  
  <pre><code>&lt;?php
  
      $photoURL = $_POST['photoURL'];
      $caption = $_POST['photoCaption'];
      $message = $_POST['photoMessage'];
  
      $fbconfig['appid' ] = "--hidden--";
      $fbconfig['secret'] = "--hidden--";
      $fbconfig['baseurl'] = "http://www.jhublerdesign.com/proofStar/dashboard.php";
      $user = null;
  
      try {
          include_once "facebook.php";
      } catch(Exception $o) {
          error_log($o);
      }
  
      $facebook = new Facebook(array(
          'appId'  =&gt; $fbconfig['appid'],
          'secret' =&gt; $fbconfig['secret'],
          'cookie' =&gt; true,
      ));
  
      $user = $facebook-&gt;getUser();    
      $loginUrl = $facebook-&gt;getLoginUrl(
          array(
              'scope' =&gt; 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
              'redirect_uri' =&gt; $fbconfig['baseurl']
          )
      );
  
      $logoutUrl  = $facebook-&gt;getLogoutUrl();
  
  
      if ($user) {
          try {
              $user_profile = $facebook-&gt;api('/me');
          } catch (FacebookApiException $e) {
              d($e);
              $user = null;
          }
      }
  
      if ($user) {
          try {
              $publishStream = $facebook-&gt;api("/$user/feed", 'post', array(
                  'message' =&gt; "This photo has been posted from ProofStar!", 
                  'link'    =&gt; $photoURL,
                  'picture' =&gt; $photoURL,
                  'name'    =&gt; 'DSC_1234',
                  'description'=&gt; $message
              ));
              echo "success";
          } catch (FacebookApiException $e) {
              echo $e;
          }
      }
  ?&gt;
  </code></pre>
  
  <p>So, with all of that said - whenever I submit the form to AJAX, it returns as an error, but does not show me what error it is, and it most certainly does not post to Facebook.</p>
  
  <p>Any ideas what I am missing?  Any help would be appreciated!  Thank you!</p>