如何在 oriceon/oauth-5-laravel 推特 api 中实施 friendships/exists?
how to implement friendships/exists in oriceon/oauth-5-laravel twitter api?
我正在使用 oriceon/oauth-5-laravel 。帮助我实施 friendships/exists。我想 post 一个请求以遵循特定的 person.help me.tysm提前
考虑一下您想在推特上关注 NASA 的情况。NASA 是 NASA[ 的屏幕名称=16=]。您应该将屏幕名称添加到 url 作为 below.Add 此方法到您的控制器并进行适当的路由。
public function followWithTwitter(Request $request)
{
$token = $request->get('oauth_token');
$verify = $request->get('oauth_verifier');
$tw = \OAuth::consumer('Twitter');
if ( ! is_null($token) && ! is_null($verify))
{
// This was a callback request from twitter, get the token
$token = $tw->requestAccessToken($token, $verify);
// Send a request with it
$result = json_decode($tw->request('https://api.twitter.com/1.1/friendships/create.json?screen_name=NASA&follow=true','POST'), true);
if (!$result){
//do some tasks for calculating and database updation for following
return ("failed");
}
else{
//do some tasks for calculating and database updation for following
return ("success");
}
}
// if not ask for permission first
else
{
// get request token
$reqToken = $tw->requestRequestToken();
// get Authorization Uri sending the request token
$url = $tw->getAuthorizationUri(['oauth_token' => $reqToken->getRequestToken()]);
// return to twitter login url
return redirect((string)$url);
}
}
我正在使用 oriceon/oauth-5-laravel 。帮助我实施 friendships/exists。我想 post 一个请求以遵循特定的 person.help me.tysm提前
考虑一下您想在推特上关注 NASA 的情况。NASA 是 NASA[ 的屏幕名称=16=]。您应该将屏幕名称添加到 url 作为 below.Add 此方法到您的控制器并进行适当的路由。
public function followWithTwitter(Request $request)
{
$token = $request->get('oauth_token');
$verify = $request->get('oauth_verifier');
$tw = \OAuth::consumer('Twitter');
if ( ! is_null($token) && ! is_null($verify))
{
// This was a callback request from twitter, get the token
$token = $tw->requestAccessToken($token, $verify);
// Send a request with it
$result = json_decode($tw->request('https://api.twitter.com/1.1/friendships/create.json?screen_name=NASA&follow=true','POST'), true);
if (!$result){
//do some tasks for calculating and database updation for following
return ("failed");
}
else{
//do some tasks for calculating and database updation for following
return ("success");
}
}
// if not ask for permission first
else
{
// get request token
$reqToken = $tw->requestRequestToken();
// get Authorization Uri sending the request token
$url = $tw->getAuthorizationUri(['oauth_token' => $reqToken->getRequestToken()]);
// return to twitter login url
return redirect((string)$url);
}
}