短いビデオプラットフォームの台頭により、Kuaishouは多くの人々が自分の生活を共有し、才能を示すための重要なプラットフォームになりました。開発者の場合、Kuaishou APIインターフェイスを使用すると、ユーザー関連の情報を簡単に取得できます。この記事では、PHPを使用してKuaishou APIインターフェイスを開発して、ユーザーのファンとフォロワーリストを作成する方法を紹介します。
Kuaishou APIインターフェイスを使用する前に、アクセストークン(アクセストークン)を取得する必要があります。 Kuaishou開発者プラットフォームを介してアプリケーションを申請し、関連するAPIキーとキーを取得できます。次に、次のコードを使用してアクセストークンを取得できます。
$ clientId = 'your_client_id'; $ clientsecret = 'your_client_secret'; $ redirecturi = 'your_redirect_uri'; $ authorizeurl = 'https://api.kuaishouzt.com/rest/2.0/oauth2/authorize?client_id='。 $ clientid。 '&redirect_uri ='。 urlencode($ redirecturi)。 '&Response_type = code'; Header( 'location:'。$ authorizeurl);
上記のコードを介して、ユーザーはKuaishouログインページにリダイレクトされ、アクセストークンを取得します。
ユーザーのフォロワーとフォロワーリストを取得する前に、最初にユーザーのIDを取得する必要があります。次のコードを使用して、ユーザーIDを取得できます。
$ code = $ _get ['code']; $ AccessTokenurl = 'https://api.kuaishouzt.com/rest/2.0/oauth2/access_token?client_id='。 $ clientid。 '&client_secret ='。 $ clientsecret。 '&code ='。 $ code; $ response = file_get_contents($ accesstokenurl); $ AccessToken = json_decode($ response、true)['Access_token']; $ userinfourl = 'https://api.kuaishouzt.com/rest/2.0/me?access_token='。 $ accesstoken; $ response = file_get_contents($ userinfourl); $ userid = json_decode($ response、true)['id'];
上記のコードを通じて、ユーザーのIDを取得でき、その後の操作はこのIDに基づいています。
Kuaishou APIインターフェイスを介して、ユーザーのファンリストを簡単に取得できます。次のコードを使用して、ユーザーのファン情報を取得します。
$ FOLORERSURL = 'https://api.kuaishouzt.com/rest/2.0/users/'。 $ userid。 '/フォロワー?access_token ='。 $ accesstoken; $ response = file_get_contents($ followersurl); $ FOLORES = JSON_DECODE($ response、true)['FOLORES']; foreach($フォロワーとしてのフォロワー){ $ followerid = $ follower ['id']; $ followername = $ follower ['name']; エコー「ファンID:」。 $ followerid。 "、ファン名前:"。 $ followername。 「<br> "; }
上記のコードを介して、ユーザーのファンリストを取得し、データをさらに処理できます。
同様に、Kuaishou APIインターフェイスを使用して、ユーザーの注意リストを取得することもできます。ユーザーの注意リストを取得するためのコードは次のとおりです。
$ follofurl = 'https://api.kuaishouzt.com/rest/2.0/users/'。 $ userid。 '/follow?access_token ='。 $ accesstoken; $ response = file_get_contents($ follofurl); $ follow = json_decode($ response、true)['follow']; foreach($ follow as $ follow){ $ followid = $ follow ['id']; $ followname = $ follow ['name']; エコー「IDフォロー:」。 $ followid。 "、フォロー名前:"。 $ follouname。 「<br> "; }
上記のコードを介して、ユーザーの注意リストを取得し、それに応じて処理できます。
この記事では、PHPを介してKuaishou APIインターフェイスを開発して、ユーザーのファンとフォロワーリストを作成する方法を紹介します。アクセストークン、ユーザーIDSの取得からファン、フォロワーの取得まで、データ処理と表示を容易にする完全な開発プロセスを実証しました。このガイドが開発の取り組みに役立つことを願っています!