2015-08-26 64 views
0

我創建了一個應用程序,通過angularjs前端和Laravel後端工作登錄到Twitter並使用Satellizer庫。使用Twitter API與Laravel AngularJS衛星

現在我想使用由衛星產生的oAuth與Twitter Rest API進行交互,是否有人有建議或圖書館來做到這一點?我已經檢出了thujohn/twitter Laravel插件,但是我不能用它與Satellizer一起玩,它不覆蓋我想要的所有api調用(搜索推文,回覆推文,獲取用戶時間軸,獲取配置文件)

All help不勝感激!

劉易斯

回答

0

對於在類似情況下別人:我覺得最簡單的只寫我自己的函數,而不是使用第二個庫。

舉例路線: Route::post('tweet', ['middleware' => 'auth', 'uses' => '[email protected]']); 例控制器功能: 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嘰嘰喳喳廠: 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); }); }); };