2

私はこのスクリプトを持っています: このコードはテキストと Web サイトへのリンクを投稿する必要があります

<?
  // Remember to copy files from the SDK's src/ directory to a
  // directory in your application on the server, such as php-sdk/
  require_once('facebook.php');

  $c = array(
    'appId' => '4102137023*****',
    'secret' => '*****c4a60cb08*****7c0333*****',
  );

  $facebook = new Facebook($c);
  $uid = $facebook->getUser();
  echo "Userid: " . $uid;
  echo "<BR>";
?>
<html>
  <head></head>
  <body>

  <?
    if($uid){

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {
        $ret_obj = $facebook->api('/me/feed', 'POST',
                                    array(
                                      'link' => 'angel-craft.de',
                                      'message' => 'Wenn ihr das hier seht freut euch auf ein Game'
                                 ));
        echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';

      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl( array(
                       'scope' => 'publish_stream'
                       )); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        echo $e->getType();
        echo $e->getMessage();
      }   
      // Give the user a logout link 
      echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
    } else {

      // No user, so print a link for the user to login
      // To post to a user's wall, we need publish_stream permission
      // We'll use the current URL as the redirect_uri, so we don't
      // need to specify it here.
      $login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }
  ?>

  </body>
</html>

これにより、テキスト付きのリンクが投稿されますが、Userid($uid) は空のままです。

はい、これは FB dev のデモ スクリプトです。

4

2 に答える 2

0

私はこれをうまく使いました。

<?php 
require 'src/facebook.php';

    // Create our Application instance (replace this with your appId and secret).
    $facebook = new Facebook(array(
      'appId'  => '-----',
      'secret' => '-----',
      'cookie' => true,
    ));

    $session = $facebook->getSession();

    $me = null;
    // Session based API call.
    if ($session) {
      try {
        $uid = $facebook->getUser();
        $me = $facebook->api('/me');



        $Name = $me['first_name'];


        $properties = array(
                              array(
                                    'text'=>'Property Link', 
                                    'href'=>'http://www.yahoo.com'
                                    ),
                              array(
                                    'text'=>'Property Link', 
                                    'href'=>'http://www.yahoo.com'
                                    )
                              );

        // Link that is adjacent to "Like" and "Comment" at the very bottom of the post.
        $action_links = array(
                              'name'=>'Test', 
                              'link'=>'http://www.yahoo.com'
                              );
        // Dictates who can see the post.
        $privacy = array(
                         'value'=>'ALL_FRIENDS'
                         );

        // api('/me/feed', 'post',... = Wall Post.
        $wallPost = $facebook->api('me/feed', 'post', array(
                                                                 'message'=> 'Testing',                                     
                                                                 'link'=> 'http://www.yahoo.com',
                                                                                                                                 'properties'=>$properties,
                                                                 'actions'=>$action_links                                                           
                                                                 )
                                       );




      } catch (FacebookApiException $e) {

        error_log($e);
      }
    }

    $par = array();
    $par['req_perms'] = "email, publish_stream";


    if ($me) {
      $logoutUrl = $facebook->getLogoutUrl();
    } else {
      $loginUrl = $facebook->getLoginUrl($par);
    }
    ?>
于 2012-12-04T17:41:46.157 に答える
0

バグが見つかりました。証明書が古かったです。ありがとうございます :)

于 2012-12-04T17:58:43.147 に答える