LoginSignup
0
0

More than 3 years have passed since last update.

laravel cowitter

Posted at

laravel で twitter api cowitter を使う。
面倒なのでモデルに読み込ませる。

これで片思いかどうかがわかる。

Cow.php

<?php

namespace App;
use Illuminate\Database\Eloquent\Model;
use Log;

use mpyw\Co\Co;
use mpyw\Co\CURLException;
use mpyw\Cowitter\Client;
use mpyw\Cowitter\HttpException;

//cowitter 利用専門
class Cow extends Model
{

    var $client;

    public function start($token,$token_secret)
    {
        $client = new Client([config('app.twitter_client_id'),config('app.twitter_client_secret'),$token,$token_secret]);
        $this->client = $client;
    }


    public function isFollow($source_id,$target_id)
    {
        //片思い
        $statuses = $this->client->get('friendships/show', [
            'source_id' => $source_id,
            'target_id' => $target_id,
        ]);

        if($statuses->relationship->source->following){
//            pd("フォローしています");
            $res = true;
        } else {
//            pd("フォローしていません");
            $res = false;
        }

        return $res;
    }


}



cowitter

HogeController.php

use App\Cow;
class HogeController extends Controller
{

    public static function test(Request $request)
    {

        $token = '4yhournZLGNGD';
        $token_secret = 'tWuyiur34QFkbdBEDONuAybqBaagr';

        $cow = new Cow;
        $cow->start($token,$token_secret);
        $tmp = $cow->isFollow('125023968', '11285142');
//        $tmp = $cow->isFollow('11285142','125023968');

        pd($res);

        die;

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0