Twitter提供了一种简单的方法,可以预先确定某人的发布状态。具体来说,它就像http://twitter.com/?status=message一样简单。
我正在寻找一种类似于facebook的方法。不幸的是,我能找到的只是按钮和类似的东西,它们不符合我的需要(我们想要发布的内容没有自己的页面)。 Facebook上有什么方法可以轻松设置某人的状态吗?
答案 0 :(得分: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中说这个,这应该几乎涵盖了他们对Sharer页面的政策:
此字段将在2011年7月12日被忽略预填充用户将键入的文本字段的消息。要符合Facebook平台策略,您的应用程序可能仅在用户先前手动生成内容时设置此字段在工作流程中。大多数应用程序不应该设置它。
答案 1 :(得分:0)
答案 2 :(得分:-1)
在Facebook中,要发布到某个用户的个人资料,您需要以下内容:
publish_stream
)现在做的很简单,可以通过不同的方式完成,让我们使用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以帮助您入门。