2011-03-01 87 views
0

Twitter提供了一种简单的方法,用于预先准备发布某人的状态。具体来说,它就像http://twitter.com/?status=message一样简单。链接到Facebook上的预填状态

我正在寻找类似的方法来使用Facebook。不幸的是,我能找到的所有内容都像按钮和类似的东西,这不符合我的需要(我们要发布的内容没有自己的页面)。 Facebook上是否有任何方法可以轻松设置某些人的身份?

回答

-1

在Facebook上,张贴到某个用户的个人资料,你需要以下条件:

  1. 验证/授权您的应用
  2. 你问的扩展权限才能张贴到他的墙用户(在这种情况下publish_stream
  3. 捕获用户ID,并用它来发布你想要的任何

现在做很容易,可以用不同的方式,L完成等的乘坐PHP-SDK example页面并修改它:

<?php 
/** 
* Copyright 2011 Facebook, Inc. 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); you may 
* not use this file except in compliance with the License. You may obtain 
* a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
* License for the specific language governing permissions and limitations 
* under the License. 
*/ 

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

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

// Get User ID 
$user = $facebook->getUser(); 

// We may or may not have this data based on whether the user is logged in. 
// 
// If we have a $user id here, it means we know the user is logged into 
// Facebook, but we don't know if the access token is valid. An access 
// token is invalid if the user logged out of Facebook. 

if ($user) { 
    try { 
    // Proceed knowing you have a logged in user who's authenticated. 
    $user_profile = $facebook->api('/me'); 
    } catch (FacebookApiException $e) { 
    error_log($e); 
    $user = null; 
    } 
} 

// Login or logout url will be needed depending on current user state. 
if ($user) { 
    $logoutUrl = $facebook->getLogoutUrl(); 
} else { 
    $loginUrl = $facebook->getLoginUrl(
    'scope' => 'publish_stream' 
); 
} 

// This call will always work since we are fetching public data. 
$naitik = $facebook->api('/naitik'); 

?> 
<!doctype html> 
<html xmlns:fb="http://www.facebook.com/2008/fbml"> 
    <head> 
    <title>php-sdk</title> 
    <style> 
     body { 
     font-family: 'Lucida Grande', Verdana, Arial, sans-serif; 
     } 
     h1 a { 
     text-decoration: none; 
     color: #3b5998; 
     } 
     h1 a:hover { 
     text-decoration: underline; 
     } 
    </style> 
    </head> 
    <body> 
    <h1>php-sdk</h1> 

    <?php if ($user): ?> 
     <a href="<?php echo $logoutUrl; ?>">Logout</a> 
    <?php else: ?> 
     <div> 
     Login using OAuth 2.0 handled by the PHP SDK: 
     <a href="<?php echo $loginUrl; ?>">Login with Facebook</a> 
     </div> 
    <?php endif ?> 

    <h3>PHP Session</h3> 
    <pre><?php print_r($_SESSION); ?></pre> 

    <?php if ($user): ?> 
     <h3>You</h3> 
     <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> 

     <h3>Your User Object (/me)</h3> 
     <pre><?php print_r($user_profile); ?></pre> 
    <?php else: ?> 
     <strong><em>You are not Connected.</em></strong> 
    <?php endif ?> 

    <h3>Public profile of Naitik</h3> 
    <img src="https://graph.facebook.com/naitik/picture"> 
    <?php echo $naitik['name']; ?> 
    </body> 
</html> 

现在我改变了从最初的例子如下:

$loginUrl = $facebook->getLoginUrl(array(
    "scope" => "publish_stream" 
)); 

现在用户授予您的应用程序,你可以发布到正确的权限他的墙壁,请参考这个answer让你开始。

+0

介意解释倒票?! – ifaour 2011-03-01 10:57:13

1

这听起来像你只是想要一个简单的方式来分享内容到Facebook上。 Facebook正在弃用分享按钮,但似乎仍然支持直接URL调用共享页面:

http://www.facebook.com/sharer/sharer.php?u=cnn.com&t=great+news+site 

因此,创建,打开你的URL在新窗口中,像这样的Javascript链接:

window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(myUrl)+'&t='+encodeURIComponent(myTitle),'sharer','toolbar=0,status=0,width=626,height=436'); 

您提到使用默认文本预填充它。我相信Facebook现在明确禁止这一点。他们说,这在Feed Dialog page,应该差不多捂政策共享者页面太:

该领域将在2011年7月12日被忽略预填的文本字段,用户将输入的消息。为了符合Facebook平台政策,如果用户在工作流程的早期手动生成内容,您的应用程序可能只会设置此字段。大多数应用程序不应该设置它。