Question

Is there a possibility where I can make a button on which when I click, the contents directly get shared on facebook without showing our user the share prompt dialog box?

I referred it online and found that its possible through mobile devices: http://www.mindfiresolutions.com/How-to-post-message-on-your-facebook-wall-without-using-Facebook-dialog-Box-1419.php

The question is can we make some sort of ajax call and get this done on web apps.

We used Following code

<?php
require_once('php-sdk/facebook.php');
$config = array(
  'appId' => 'My app ID', /*Your APP ID*/
  'secret' => 'My Secret ID', /*Your APP Secret Key*/
  'allowSignedRequest' => false 
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();

  if($user_id) {
    try {
      $user_profile = $facebook->api('/me','GET');

    } catch(FacebookApiException $e) {
      $login_url = $facebook->getLoginUrl(); 
      echo 'Please <a href="' . $login_url . '">login.</a>';
      error_log($e->getType());
      error_log($e->getMessage());
    }   
  } else {
    // No user, print a link for the user to login
    $login_url = $facebook->getLoginUrl();
    echo 'Please <a href="' . $login_url . '">login.</a>';
  }


  $response = $facebook->api(
  "/me/feed",
  "POST",
   array (
      'message' => 'This is a test message',
      'link' => 'www.google.com'
     /*        'picture' => '{picture}',
      'caption' => '{caption}',
      'description' => '{description}'*/
  )
);
  ?>

But its returns : " Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action throw in file" Any help would be highly appreciated.

Thanks in advance.

Was it helpful?

Solution

Of course you can using the Graph API. On the button click you just have to make a \POST call to /me/feed.

Learn more about publishing a feed via Graph API and what all parameters are available here.

Permission required: publish_stream

Using PHP SDK:

$response = $facebook->api(
    "/me/feed",
    "POST",
    array (
        'message' => 'This is a test message',
        'link' => '{link}',
        'picture' => '{picture}',
        'caption' => '{caption}',
        'description' => '{description}'
    )
);

Direct HTTP Request-

POST /me/feed
Host: graph.facebook.com

message=This+is+a+test+message
...

You can check your calls in Graph API Explorer


Edit:

To ask for the required permissions:

$params = array(
  'scope' => 'publish_stream'
);

$login_url = $facebook->getLoginUrl($params);

You can read more about permissions here.

OTHER TIPS

Try this way: https://developers.facebook.com/docs/reference/php/ When coding the wep app, you only have to provide the App Id and the App Secret, then you should have to specify the content to be posted. You should try also the Javascript Facebook SDK, you'll find it here: https://developers.facebook.com/docs/javascript or you could go further and try the C# SDK, this one is a little bit more complex, but you will be able to do so much more. Have fun coding!!!

Just go to https://developers.facebook.com/docs/opengraph/

Review it and place what kind of share you want.

This is the long process to be handle so. you need to study it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top