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
- https://www.mathworks.com/matlabcentral/answers/400962
- https://www.mathworks.com/matlabcentral/answers/1660380
- https://www.mathworks.com/matlabcentral/fileexchange/34837-twitty
Hope it helps