title: How to post to a friends wall from PHP script?
body: <p>hopefully someone can help me with this odd problem.</p>
  
  <p>I have a database which stores the Facebook ID of all users who have registered, and this works just fine.</p>
  
  <p>Users can send messages to their Facebook friends through PHP script which is activated via the app.</p>
  
  <p>In my script I have a section which says that if the ID of one of your friends is NOT in the database (i.e. they are not a registered user), then post a message to their Facebook wall notifying them that someone has tried to contact them using the app. </p>
  
  <p>There is then a second database which stores the ID of people we have notified via FB, so that we do not send them multiple requests.</p>
  
  <p>The problem is that the message doesn't ever appear on their wall. The message is sent to the PHP script as a string like this:</p>
  
  <pre><code>    NSString *urlString = [@"myApp/myphp.php?"stringByAppendingString:@"task=send"];
      urlString = [urlString stringByAppendingString:@"&amp;facebookID="];
      urlString = [urlString stringByAppendingString:[friendsToSendTo objectAtIndex:i]];
      urlString = [urlString stringByAppendingString:@"&amp;message="];
      urlString = [urlString stringByAppendingString:message];
      urlString = [urlString stringByAppendingString:@"&amp;sound="];
      urlString = [urlString stringByAppendingString:chosenSoundToSend];
      urlString = [urlString stringByAppendingString:@"&amp;sendersName="];
      urlString = [urlString stringByAppendingString:myName];
  </code></pre>
  
  <p>In the PHP script, the task=send part then starts the process of sending a message to the recipient. This part works absolutely fine, the message is received with no problems at all.</p>
  
  <p>If their ID is not found it then moves on to this:</p>
  
  <pre><code>    $this-&gt;_postToFacebook($sendersName, $facebookID);
  </code></pre>
  
  <p>The _postToFacebook function looks like this:</p>
  
  <pre><code>    private function _postToFacebook($sender, $receiver)
      {
      require_once "facebook.php";
  
      //registered with developers.facebook for this particular app
      $app_id = "****************";
      $app_secret = "*****************";
  
      $facebook = new Facebook(array(
      'appId' =&gt; $app_id,
      'secret' =&gt; $app_secret,
      'cookie' =&gt; true
      ));
  
      // Get the url to redirect for login to facebook
      // and request permission to write on the user's wall.
      $login_url = $facebook-&gt;getLoginUrl(
          array('scope' =&gt; 'publish_stream')
      );
  
      // If not authenticated, redirect to the facebook login dialog.
      // The $login_url will take care of redirecting back to us
      // after successful login.
      if (! $facebook-&gt;getUser()) {
          echo &lt;&lt;&lt; EOT
      &lt;script type="text/javascript"&gt;
      top.location.href = "$login_url";
      &lt;/script&gt;;
      EOT;
  
          exit;
      }
      // Do the wall post.
      $facebook-&gt;api("/$receiver/feed", "post", array(
          message =&gt; "$sender sent you a message",
          picture =&gt; "image.jpg",
          link =&gt; "mywebsite.com",
          name =&gt; "Visit iTunes to download and reply",
          caption =&gt; "mycaption"
      ));
  
  }
  </code></pre>
  
  <p>This is seemingly the part that fails, or at least that was my initial assumption.
  However, if I manually enter the generated URL (....task=send&amp;facebookID=12345789...etc) into a browser and hit enter - the message DOES get posted to the users wall.</p>
  
  <p>So now I am completely confused. 
  When triggering via the browser, the message is received in the app if the Facebook ID is registered and is posted to FB if not. 
  From the app itself, the message is received when the recipient is registered - but the posting to FB never works. 
  Presumably I have missed some kind of permission somewhere?</p>
  
  <p>Thanks in advance to anyone who can help :-)</p>
  
  <p>Edit: In case it is a permissions thing, I should add that I have set these permissions:</p>
  
  <pre><code> if (![facebook isSessionValid]){
  
      NSArray *permissions = [[NSArray alloc] initWithObjects:
                              @"user_relationships", @"friends_relationships",
                              @"user_relationship_details", @"friends_relationship_details",
                              @"read_friendlists",@"offline_access", @"publish_stream",
                              nil];
      [facebook authorize:permissions];
      [permissions release];
  }
  </code></pre>
  
  <p>And in the facebook class I had to change these to NO otherwise it doesn't connect at all, maybe this also causes the problem?</p>
  
  <pre><code>- (void)authorize:(NSArray *)permissions {
    self.permissions = permissions;
  
     [self authorizeWithFBAppAuth:NO safariAuth:NO];
  }
  </code></pre>