필터 지우기
필터 지우기

TwitterAPI​の仕様が変わって、T​witter関数では​データにアクセスでき​ません twitte​r.mのどこを変えれ​ばよいでしょうか。

조회 수: 9 (최근 30일)
Yuji Ochiai
Yuji Ochiai 2022년 3월 19일
편집: Chetan 2024년 1월 2일
お願いいたします。2022年3月にTwitter APIの申請をしてアカウントができましたが、APIの仕様が変わって、
API Key
API Key Secret
Bearer Token
Access Token
Access Token Secret
の5つのキーが与えられます。SentimentAnalysis.mlxを使ってキーを設定してアクセスを試みましたが、Bearer Token はTwitter関数では定義されていないようで、アクセス拒否になります。Twitter APIは1.1でアカウントは設定しています。pythonなどで、アクセスすることはできますが、必要なキーは、Bearer Token だけでOKでした。twitter.mに何かを書き加えれば、使用できるか、あるいは、別な方法があるか、お教えいただけるとありがたいです。お手数ですが、アドバイスいただけるとありがたいです。

답변 (1개)

Chetan
Chetan 2024년 1월 2일
편집: Chetan 2024년 1월 2일
I understand that you're encountering challenges with the updated Twitter API, particularly with its shift to OAuth 1.0 and the requirement to use a Bearer token for authentication.
Here's how you can adapt to these changes:
1. Custom Implementation for Twitter API:
- You can create a custom implementation to interact with the Twitter API. To pass the Bearer token in a web request, use the following MATLAB code:
headers = {'Authorization', ['Bearer ', yourBearerToken]};
options = weboptions('HeaderFields', headers);
response = webread(yourRequestURL, options);
- This code snippet sets up the necessary HTTP headers with your Bearer token and then performs the web request.
- You can automate the process of capturing the Bearer token by writing a MATLAB script that retrieves it at runtime.
2. Use Twitty Tool:
  • Twitty is a third-party Twitter API client for MATLAB that simplifies the process of interfacing with the Twitter API.
  • To get started with Twitty, follow these steps:
  • Download Twitty from the MATLAB File Exchange or GitHub.
  • Add the Twitty folder to your MATLAB path using the `addpath` function.
  • Create a `credentials.json` file containing your Twitter API keys:
{
"ConsumerKey": "YOUR_CONSUMER_KEY",
"ConsumerSecret": "YOUR_CONSUMER_SECRET",
"AccessToken": "YOUR_ACCESS_TOKEN",
"AccessTokenSecret": "YOUR_ACCESS_TOKEN_SECRET"
}
  • Load your credentials in MATLAB and instantiate a Twitty object:
credentials = loadjson('credentials.json');
twitterClient = twitty(credentials); % Creates a Twitty object
  • With the Twitty object, you can now make calls to the Twitter API using the methods provided by the Twitty class.
Refer to the following MathWorks Documentation for detailed infromation
Hope it helps

카테고리

Help CenterFile Exchange에서 MATLAB の Python ライブラリ에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!