与Laravel AngularJS Satellizer一起使用Twitter API


Use Twitter API with Laravel AngularJS Satellizer

我创建了一个应用程序,通过angularjs前端和Laravel后端使用Satellizer库登录twitter。

现在我想与Twitter Rest API进行交互,使用由satellizer生成的oAuth,有人有建议或库来做到这一点吗?我已经检查了thujohn/twitter Laravel插件,但我不能使它与Satellizer玩得很好,它不涵盖我想要的所有api调用(搜索推文,回复推文,获取用户时间线,获取个人资料)

感谢所有的帮助!

刘易斯

对于处于类似情况的其他人:我发现编写自己的函数比使用第二个库更容易。

路由示例: Route::post('tweet', ['middleware' => 'auth', 'uses' => 'TwitterController@tweet']); 控制器功能示例: public function searchTweets(Request $request) { // $url = 'https://api.twitter.com/1.1/search/tweets.json'; $client = new GuzzleHttp'Client(); $user = User::find($request['user']['sub']); $profileOauth = new Oauth1([ 'consumer_key' => Config::get('app.twitter_key'), 'consumer_secret' => Config::get('app.twitter_secret'), 'token' => $user->oauthToken, 'token_secret' => $user->oauthVerifier ]); $client->getEmitter()->attach($profileOauth); $response = $client->get($url, ['auth' => 'oauth', 'query' => ['q' => $request->input('q'), 'result_type' => $request->input('result_type'), #'since_id' => $request->input('since_id', 0), #'max_id' => $request->input('max_id', 0), 'count' => $request->input('count')] ])->json(); return $response; }

这是在我的angularJS twitter工厂: var vm = {}; vm.tweets = []; vm.busy = false; vm.outreaches = 0; vm.retweets = 0; vm.favourites = 0; vm.followed = 0; vm.status = ''; vm.since_id = null; vm.until = null; vm.max_id = null; vm.count = 100; vm.q = ''; vm.result_type = 'mixed'; /* * mixed: Include both popular and real time results in the response. * recent: return only the most recent results in the response * popular: return only the most popular results in the response. */ vm.searchTweets = function () { if (vm.busy) { return; } vm.busy = true; var url = "/twitter/search"; $http({ url: url, method: "GET", params: { q: vm.q, result_type: vm.result_type || 'mixed', count: vm.count || 100, since_id: vm.since_id || null, //until: vm.until || null, max_id: vm.max_id || null } }).then(function (response) { var newTweets = response.data.statuses; console.log('newTweets: '); console.log(newTweets); for (var i = 0; i < newTweets.length; i++) { vm.tweets.push(newTweets[i]); } vm.since_id = vm.tweets[vm.tweets.length - 1].id_str; vm.busy = false; }, function (response) { // called asynchronously if an error occurs // or server returns response with an error status. console.log(response); angular.forEach(response.data.errors, function(value, key){ $window.Materialize.toast(value.message, 3000); }); }); };