1. Go to this page and download the library: Download giko/sinaweibo-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
giko / sinaweibo-bundle example snippets
//app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new FOS\UserBundle\FOSUserBundle(),
new Giko\SinaweiboBundle\GikoSinaweiboBundle(),
// ...
);
}
friendsofsymfony/user-bundle
php
// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct() {
parent::__construct();
// your own logic
}
/**
* @var string $sinaweiboId
*
* @ORM\Column(name="sinaweibo_id", type="string", length=80, nullable=true)
*/
private $sinaweiboId;
/**
* @var string $sinaweiboUsername
*
* @ORM\Column(name="sinaweibo_username", type="string", length=100, nullable=true)
*/
private $sinaweiboUsername;
/**
* Get id
*
* @return integer $id
*/
public function getId() {
return $this->id;
}
/**
* Set sinaweiboId
*
* @param string $sinaweiboId
* @return User
*/
public function setSinaweiboId($sinaweiboId) {
$this->sinaweiboId = $sinaweiboId;
$this->setUsername($sinaweiboId);
return $this;
}
/**
* Get sinaweiboId
*
* @return string
*/
public function getSinaweiboId() {
return $this->sinaweiboId;
}
/**
* Set sinaweiboUsername
*
* @param string $sinaweiboUsername
* @return User
*/
public function setSinaweiboUsername($sinaweiboUsername) {
$this->sinaweiboUsername = $sinaweiboUsername;
return $this;
}
/**
* Get sinaweiboUsername
*
* @return string
*/
public function getSinaweiboUsername() {
return $this->sinaweiboUsername;
}
}
php
namespace Acme\UserBundle\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class SinaController extends Controller {
/**
* @Route("/sinaweibo/login", name="connect_sinaweibo")
*
*/
public function sinaAction()
{
$request = $this->get('request');
$sinaweibo = $this->get('giko_sinaweibo.service');
$authURL = $sinaweibo->getLoginUrl($request);
$response = new RedirectResponse($authURL);
return $response;
}
/**
* @Route("/sinaweibo/login_check", name="logincheck_sinaweibo")
*/
public function logincheckSinaweiboAction()
{
echo "";
}
/**
* @Route("/sinaweibo/callback", name="callback_sinaweibo")
*
*/
public function callbackSinaweiboAction()
{
/**
* @return Response
*
* @throws AccessDeniedException
*/
$user = $this->getUser();
$sinaweibo = $this->get('giko_sinaweibo.service');
$sinaInfo = $sinaweibo->getClient()->show_user_by_id($user->getSinaweiboId());
$data = array('user'=>$user, 'weiboInfo' => $user);
//your logic here
$resp = var_export($data, true);
return new Response('<pre>' . $resp . '</pre>');
}
/**
* @Route("/sinaweibo/update", name="update_sinaweibo")
*
*/
public function updateAction()
{
$request = $this->get('request');
$status = $this->getRequest()->request->get('status');
$lat = $this->getRequest()->request->get('lat', null);
$lng = $this->getRequest()->request->get('lng', null);
$annotations = array();
$sinaweibo = $this->get('giko_sinaweibo.service');
$data = $sinaweibo->getClient()->update( $status, $lat, $lng, $annotations);
//your logic here
$resp = var_export($data, true);
return new Response('<pre>' . $resp . '</pre>');
}
}
<!-- inside a php template -->
echo $view['sinaweibo_anywhere']->setup()
<!-- inside a php template -->
<span id="sinaweibo_connect"></span>
$view['sinaweibo_anywhere']->setConfig('callbackURL', 'http://www.example.com/login_check')
<!-- inside a php template -->
$view['sinaweibo_anywhere']->initialize()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.