1
IAM使用oriceon/oauth-5-laravel。幫助我實現友誼/存在。我想張貼的請求遵循特定person.help me.tysm提前如何在oriceon/oauth-5-laravel twitter api中實現友誼/存在?
IAM使用oriceon/oauth-5-laravel。幫助我實現友誼/存在。我想張貼的請求遵循特定person.help me.tysm提前如何在oriceon/oauth-5-laravel twitter api中實現友誼/存在?
考慮要遵循NASA在嘰嘰喳喳的情況。 NASA是NASA的屏幕名稱。您應該爲網址添加屏幕名稱,如下所示。將此方法添加到您的控制器並進行適當的路由。
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);
}
}