gpt4 book ai didi

php - 在PHP中使用hybridauth时如何更新用户状态?

转载 作者:行者123 更新时间:2023-12-04 05:40:23 25 4
gpt4 key购买 nike

我正在尝试使用 Hybridauth 与 facebook、twitter、linkedin 等社交网站建立联系。
这就是我与社交网站建立联系的方式。我是 PHP 新手,刚开始学习和做这件事。
index.php

<?php
# start a new PHP session
session_start();

// we need to know it
$CURRENT_URL = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
// print "CURRENT_URL $CURRENT_URL";
// change the following paths if necessary
$config = dirname(__FILE__) . '/hybridauth/config.php';
require_once( "hybridauth/Hybrid/Auth.php" );

try{
$hybridauth = new Hybrid_Auth( $config );
}
catch( Exception $e ){
echo "Ooophs, we got an error: " . $e->getMessage();
}

$provider = "";

// handle logout request
if( isset( $_GET["logout"] ) ){
$provider = $_GET["logout"];

$adapter = $hybridauth->getAdapter( $provider );

$adapter->logout();

header( "Location: index.php" );

die();
}

// if the user select a provider and authenticate with it
// then the widget will return this provider name in "connected_with" argument
elseif( isset( $_GET["connected_with"] ) && $hybridauth->isConnectedWith( $_GET["connected_with"] ) ){
$provider = $_GET["connected_with"];

$adapter = $hybridauth->getAdapter( $provider );

$user_data = $adapter->getUserProfile();

// include authenticated user view
include "authenticated_user.php";

die();
} // if user connected to the selected provider

// if not, include unauthenticated user view
include "unauthenticated_user.php";

authenticated_user.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<style type="text/css" media="screen">
<!--
BODY {
margin: 10px;
padding: 0;
}
H1 {
margin-bottom: 2px;
font-family: Garamond, "Times New Roman", Times, Serif;
}
FIELDSET {
border: 1px solid #ccc;
padding: 1em;
margin: 0;
}
LEGEND {
color: #666666;
}
-->
</style>
</head>
<body>
<br /><br />
<center>
<h1>Welcome <?php echo $user_data->displayName; ?></h1>
<br />
<br />

<table width="600" border="0" cellpadding="2" cellspacing="2">
<tr>
<td valign="top"><fieldset>
<legend>Connected user badge</legend>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td width="100" rowspan="5">
<?php
if( $user_data->photoURL ){
?>
<a href="<?php echo $user_data->profileURL; ?>"><img src="<?php echo $user_data->photoURL; ?>" title="<?php echo $user_data->displayName; ?>" border="0" width="100" height="120"></a>
<?php
}
else{
?>
<img src="avatar.png" title="<?php echo $user_data->displayName; ?>" border="0" >
<?php
}
?>
</td>
<td width="60" nowrap><div align="right"><strong>Provider</strong></div></td>
<td align="left" ><?php echo $adapter->id; ?></td>
</tr>
<tr>
<td nowrap><div align="right"><strong>Identifier</strong></div></td>
<td align="left"><?php echo $user_data->identifier; ?></td>
</tr>
<tr>
<td nowrap><div align="right"><strong>Dispaly name</strong></div></td>
<td align="left"><?php echo $user_data->displayName; ?></td>
</tr>
<tr>
<td nowrap><div align="right"><strong>Email</strong></div></td>
<td align="left"><?php
if( $user_data->email ){
echo $user_data->email ;
}
else{
echo "not provided by " . $adapter->id ;
}
?></td>
</tr>
<tr>
<td nowrap valign="top"><div align="right"><strong>Profile URL</strong></div></td>
<td align="left" valign="top"><?php echo $user_data->profileURL; ?></td>
</tr>
<tr>
<td align="right"><strong>Update Status</strong></td>
<td align="center"><input name="updatestatus" id="updatestatus" /></td>
</tr>
</table>

</fieldset></td>
</tr>
<tr>
<td valign="top" align="right">
<img src="arrow.gif" align="texttop" style="margin-top:-5px;" >
<a href="?logout=<?php echo $adapter->id; ?>">Log me out</a>
</td>
</tr>
</table>
</center>
</body>
</html>


unathenticated.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<style type="text/css" media="screen">
<!--
BODY {
margin: 10px;
padding: 0;
}
H1 {
margin-bottom: 2px;
font-family: Garamond, "Times New Roman", Times, Serif;
}
FIELDSET {
border: 1px solid #ccc;
padding: 1em;
margin: 0;
}
LEGEND {
color: #666666;
}
INPUT {
display: block;
font-family: Arial, verdana;
padding: 7px;
border: 1px solid #999;
margin: 10px;
}
/* Gradient 2 */
.textbox{
background-image: url(images/bg.png);
border: 1px solid #6297BC;
width: 230px;
}
-->
</style>
</head>
<body>
<br /><br />
<center>
<h1>Social web sites integration</h1>
<br />
<br />
<table width="380" border="0" cellpadding="2" cellspacing="2">
<tr>
<td valign="top"><fieldset>
<legend>Sign-in form</legend>
<table width="00%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td><div align="right"><strong>login</strong></div></td>
<td><input type="text" name="textfield" id="textfield" class="textbox"/></td>
</tr>
<tr>
<td><div align="right"><strong>password</strong></div></td>
<td><input type="text" name="textfield2" id="textfield2" class="textbox"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">
<input type="submit" value="Sign-in" />
</div></td>
</tr>
</table>
</fieldset></td>
</tr>
<tr>
<td valign="top" align="right">
<!--img src="arrow.gif" align="texttop" style="margin-top:-5px;" -->
<!-- CODE REQUIRED BY THE WIDGET -->
<link media="screen" rel="stylesheet" href="widget/css/colorbox.css" />
<script src="widget/js/jquery.min.js"></script>
<script src="widget/js/jquery.colorbox.js"></script>
<script>
$(document).ready(function(){
$(".widget_link").colorbox({iframe:true, innerWidth:430, innerHeight:222});
});
</script>
<!-- /WIDGET -->
<!--
LINK TO THE WIDGET
return_to: call back this page after authenticatin the user
ts: nocache
-->
<a href="widget/?_ts=<?php echo time(); ?>&return_to=<?php echo urlencode( $CURRENT_URL ); ?>" class='widget_link' title="Socail web sites linker">Or sign-in with Social web sites</a>
</td>
</tr>
</table>
<br /><br /><br />
<!--b>Note:</b> This is just a proof of concept! it works good enough to try out on Firefox or on Chrome.-->
</center>
</body>
</html>

所以请帮助我如何解决这个问题?,在这里我确实显示了用户信息,例如名字和姓氏以及图片网址。我想添加另一个文本框,可以更新用户状态或贴墙。

最佳答案

来自用户指南:Update User Status

这种方法存在:$adapter->setUserStatus("");
用户指南中的注释:
目前只有 Facebook、Twitter、Identica、LinkedIn、QQ、新浪、Murmur、Pixnet 和 Plurk 支持此功能

您可以在 authenticated_user.php 上创建表单并添加 ID 为“status_update”的文本字段。提交后,您可以检查它并运行 setUserStatus 方法。

// if the user select a provider and authenticate with it
// then the widget will return this provider name in "connected_with" argument
elseif( isset( $_GET["connected_with"] ) && $hybridauth->isConnectedWith( $_GET["connected_with"] ) ){
$provider = $_GET["connected_with"];

$adapter = $hybridauth->getAdapter( $provider );


// *****************************************************
// NEW CODE TO UPDATE USER STATUS
if( isset( $_GET["status_update"] ) && !empty( $_GET["status_update"] ) ) {
$adapter->setUserStatus( $_GET["status_update"] );
}


$user_data = $adapter->getUserProfile();

// include authenticated user view
include "authenticated_user.php";

die();
} // if user connected to the selected provider

关于php - 在PHP中使用hybridauth时如何更新用户状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11328777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com