Is there any way to retrieve your own tweet organic_metrics and at the same time the referenced_tweets without theirs Twiter API V2 - twitter

I am trying to request my own timeline tweets organic_metrics by adding them on the tweet.fields. By doing so, I retrieve them as expected.
The problem is that if I add the expansions referenced_tweets.id,referenced_tweets.id.author_id to the query I get a Field Authorization Error because (I presume) its attempting to retrieve the organic_metrics from the referenced tweets.
Here is an error example:
{
"resource_type": "tweet",
"field": "organic_metrics.like_count",
"parameter": "referenced_tweets.id",
"resource_id": "1602665220689764353",
"title": "Field Authorization Error",
"section": "includes",
"detail": "Sorry, you are not authorized to access 'organic_metrics.like_count' on the Tweet with referenced_tweets.id : [1602665220689764353].",
"value": "1602665220689764353",
"type": "https://api.twitter.com/2/problems/not-authorized-for-field"
},
With this error the referenced_tweets do not come in the response and therefore I am unable to retrieve my own tweets organic_metrics and the referenced_tweets in the same response.
I am forced to do x2 queries 🫠
I understand I can not access the organic_metrics on the referenced_tweets and I don't want to, I just need my own organic_metrics.
Is there any way to tell the API that I just want the organic_metrics of my tweets while at the same time retrieve the referenced_tweets without organic_metrics?

Related

How to filter tweets for bots and influential account or account of interest using twitter v2 api

I am using twitter v2 apis for getting the count and tweets. I am trying to fetch tweets based on some hashtag. I want to filter the tweets on some criteria before fetching them so that I can save the allowed quota. The documentation says that I can use followers_count or listed_count or filter the bots using -bio:bot -bio_name:bot -bio_location:bot -bio:TwitterBot -bio_name:TwitterBot -bio_location:TwitterBot but the api response for these filters is invalid operator.
How can I use these operators in v2 api to filter the tweets?
POST EDITED:
so my request where I use followers_count is like this
https://api.twitter.com/2/tweets/counts/all?query=(%23bitcoin OR %23BTC) lang:en -is:retweet -is:reply -is:quote -is:nullcast followers_count:5000&start_time=2022-03-01T00:00:00Z&granularity=day
The response is
{
"errors": [
{
"parameters": {
"query": [
"(#bitcoin OR #BTC) lang:en -is:retweet -is:reply -is:quote -is:nullcast followers_count:5000"
]
},
"message": "There were errors processing your request: Reference to invalid operator 'followers_count'. Operator is not available in current product or product packaging. Please refer to complete available operator list at https://developer.twitter.com/en/docs/twitter-api/enterprise/rules-and-filtering/operators-by-product. (at position 73)"
}
],
"title": "Invalid Request",
"detail": "One or more parameters to your request was invalid.",
"type": "https://api.twitter.com/2/problems/invalid-request"
}
I get similar response for using bot query like -bio:bot -bio_name:bot -bio_location:bot -bio:TwitterBot -bio_name:TwitterBot -bio_location:TwitterBot or listed_count.
If I remove these operators, the api works fine.

Using RSC To Access Chat Messages with Microsoft Graph

I am building a Teams chat-bot that looks at the history of messages in the current chat/channel whilst in conversation with the user.
My bot has been granted all the RSC (Resource-Specific Content) Permissions it needs (see image below)
Here is the relevant parts of the manifest:
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.11/MicrosoftTeams.schema.json",
"version": "1.0.0",
"manifestVersion": "1.11",
"id": "bd33f8b1-b593-433c-926e-44a27c1bd94a",
...
"permissions": [
"identity",
"messageTeamMembers"
],
...
"bots": [
{
"botId": "e6d93739-a8ab-412d-a4f6-b6f514a3451a",
"scopes": [
"team",
"personal",
"groupchat"
],
"isNotificationOnly": false,
"supportsFiles": true
}
],
"validDomains": [],
"webApplicationInfo": {
"id": "e6d93739-a8ab-412d-a4f6-b6f514a3451a",
"resource": "https://RscBasedStoreApp",
"applicationPermissions": [
"TeamSettings.Read.Group",
"ChannelMessage.Read.Group",
"TeamSettings.Edit.Group",
"ChannelSettings.ReadWrite.Group",
"Channel.Create.Group",
"Channel.Delete.Group",
"TeamsApp.Read.Group",
"TeamsTab.Read.Group",
"TeamsTab.Create.Group",
"TeamsTab.ReadWrite.Group",
"TeamsTab.Delete.Group",
"Member.Read.Group",
"Owner.Read.Group",
"ChatSettings.Read.Chat",
"ChatSettings.ReadWrite.Chat",
"ChatMessage.Read.Chat",
"ChatMember.Read.Chat",
"Chat.Manage.Chat",
"TeamsTab.Read.Chat",
"TeamsTab.Create.Chat",
"TeamsTab.Delete.Chat",
"TeamsTab.ReadWrite.Chat",
"TeamsAppInstallation.Read.Chat",
"OnlineMeeting.ReadBasic.Chat",
"Calls.AccessMedia.Chat",
"Calls.JoinGroupCalls.Chat",
"TeamsActivity.Send.Chat"
]
}
}
Note: the bot has permission to read messages in chats and channels. Specifically, my problem affects chats and not channels (which I can get messages from fine).
In order to do this, I get a JWT token for the bot account, accessing the Graph API like so:
GraphServiceClient<?> gsc = GraphServiceClient.builder()
.authenticationProvider(u -> mac.getToken())
.buildClient();
Next, I am using the Graph API to pull back these messages. For messages in channels I can do:
gsc.teams("some group id")
.channels("team id")
.messages()
.buildRequest(Collections.emptyList()).get()));
This works fine.
For chats, I am doing something like:
gsc.chats("29:13qY8hmfkJinH9-v7rYKjCNFHYFJXKbjqR-NyzyKzL694npelHJoq5HrVtqJLRYo79OYeHGQq-bhtJM5N-yKXyQ")
.messages()
.buildRequest().get()));
However, this time I get an error from the Graph API:
[Some information was truncated for brevity, enable debug logging for
more details] com.microsoft.graph.http.GraphServiceException: Error
code: Forbidden Error message: Invoked API requires Protected API
access in application-only context when not using Resource Specific
Consent. Visit
https://learn.microsoft.com/en-us/graph/teams-protected-apis for more
details.
GET
https://graph.microsoft.com/v1.0/chats/29:13qY8hmfkJinH9-v7rYKjCNFHYFJXKbjqR-NyzyKzL694npelHJoq5HrVtqJLRYo79OYeHGQq-bhtJM5N-yKXyQ/messages
SdkVersion : graph-java/v5.6.0
I am at a loss to explain why querying channels works fine but querying chats fails.
Any help gratefully appreciated!
This is a protected API and in order to use it you will first need to make a formal request to Microsoft Graph, asking for permissions to use the API without any user interaction
Here is the list of protected APIs. You need to fill this form to get the required permissions.
To request access to these protected APIs, complete the following
request form. We review access requests every Wednesday and deploy
approvals every Friday, except during major holiday weeks in the U.S.
Submissions during those weeks will be processed the following
non-holiday week.
The other option would be to use delegated flow.

groupPolicyConfigurations/{groupPolicyConfigurationId}/updateDefinitionValues can't update configuration with API

I am trying to update my Microsoft Intune Configuration using Microsoft Graph API.
For this I am using Postman. I have set up an app registration to assign the needed permissions and retrieve an access token. This is working in so far that I can read most of my configurations.
Now I am trying to change a configuration using POST /deviceManagement/groupPolicyConfigurations/{groupPolicyConfigurationId}/updateDefinitionValues. (Docs)
Now the problem is when I forming the request according to the docs:
{ "added":[],
"updated":[{
"#odata.type": "#microsoft.graph.groupPolicyDefinitionValue",
"createdDateTime": "2017-01-01T00:02:43.5775965-08:00",
"enabled": true,
"configurationType": "policy",
"id": "<id>",
"lastModifiedDateTime": "2017-01-01T00:00:35.1329464-08:00"
}],
"deletedIds":[]}
I get:
error code: BadRequest
"date": "2020-11-04T19:04:33",
"request-id": "c66c508b-0f73-4e7f-966a-97bf460818be",
I also tried to inspect the requests sent by the Azure Portal when changing the it in the UI and the Graph API request sent by the UI is quite a bit different than the one from the docs:
{ "added":[],
"updated":[{
"id":"<id>",
"enabled":true,
"presentationValues":[],
"definition#odata.bind":"https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('<id>')"
}],
"deletedIds":[]}
and this one returns a HTTP 403 Forbidden I get a
error code: BadRequest
"date": "2020-11-04T19:04:27",
"request-id": "c70d67bc-b4d4-40cc-b2c9-7d60896f972a",
Unfortunately the response does not contain any information on what exactly the issue is and I don't know if there is any logs where I could find a more detailed error description.
Does anybody have experience with this and knows where I could get the correct payload for the request?

Impossible to get messages details in a list request with Gmail API

I am using a ruby on rails app which connects to the Gmail API. When I make a listrequest to get all the messages of one mailbox, I only get back an idand a threadId property for each message.
I tried to follow Gmail API Doc using the fields parameters to get other properties (title, date...). It doesn't work, whether I use the google-api-client gem in my app, or by doing a direct GET request.
Adding any other parameters to the request ends with a failure. Here is the url that works :
https://www.googleapis.com/gmail/v1/users/me/messages?fields=messages(id,threadId)
Am I forced to make one call per message or using batch requests to get relevant datas ? It seems a little heavy...
You first need to list messages like you've done, and then get each message in a separate request.
Request 1
GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1&access_token={ACCESS_TOKEN}
Response 1
{
"messages": [
{
"id": "15fd9f0fe242f975",
"threadId": "15fd9f0fe242f975"
}
],
"nextPageToken": "11889180580605610074",
"resultSizeEstimate": 2
}
Request 2
GET https://www.googleapis.com/gmail/v1/users/me/messages/15fd9f0fe242f975?access_token={ACCESS_TOKEN}
Response 2
{
"id": "15fd9f0fe242f975",
"threadId": "15fd9f0fe242f975",
"labelIds": [
"IMPORTANT",
"CATEGORY_UPDATES",
"INBOX"
],
"snippet": "Tasks tracked last week...",
"historyId": "966691",
...
}
It's also possible to get the total amount of request down from 1 + n of messages to 2 by using batch requests.

Retrieving date of birth with Google OAuth API

Does any one know how to retrive D.O.B through Google OAuth api? I am able to get other information like name, email, gender by setting the scope as https://www.googleapis.com/auth/userinfo.profile. But I am not able to get D.O.B with this scope.
I definitely get it for my account:
{
"id": "108635752367054807758",
"name": "Nicolas Garnier",
"given_name": "Nicolas",
"family_name": "Garnier",
"link": "https://plus.google.com/108635752367054807758",
"picture": "https://lh4.googleusercontent.com/-K1xGP8W20xk/AAAAAAAAAAI/AAAAAAAABhY/Cs_4qr30MxI/photo.jpg",
"gender": "male",
"birthday": "0000-08-25",
"locale": "en"
}
all I did is authorize for the https://www.googleapis.com/auth/userinfo.profile scope and then sent a GET request to https://www.googleapis.com/oauth2/v2/userinfo
First make sure that the Google+ account that you are testing with has set a Birthday (of course), then try the request on the OAuth 2.0 Playground for instance: https://code.google.com/oauthplayground/#step1&apisSelect=https%3A//www.googleapis.com/auth/userinfo.profile&url=https%3A//www.googleapis.com/oauth2/v2/userinfo
It seems you have to send 2 requests:
https://www.googleapis.com/plus/v1/people/me (oauth v1)
https://www.googleapis.com/oauth2/v2/userinfo (oauth v2)
to get both google plus profile data and google account data (there are date of birthday and also locale if you need it)
I use scribes and it works ok. Set two scopes ("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me") and send two requests for both REST links

Resources