Twitter Academic Research with japanese language - python-3.x

This is my first question. I would like to seek your advice on this matter.<(_ _)>
I got a Twitter Academic Research account. To get the tweets of a specific user, Using official sample code as a reference, I made the "param" as follows.
query_params = {'query': '(from:jtwfihT7bFRPzEx -is:retweet)','lang': 'ja', 'tweet.fields': 'author_id'}
But if I specify "lang" as an argument to the "query" parameter, I get the following error.
Exception: (400, '{"errors":[{"parameters":{"lang":["ja"]},"message":"The query parameter [lang] is not one of [query,start_time,end_time,since_id,until_id,max_results,next_token,expansions,tweet.fields,media.fields,poll.fields,place.fields,user.fields]"}],"title":"Invalid Request","detail":"One or more parameters to your request was invalid.","type":"https://api.twitter.com/2/problems/invalid-request"}')
Does Twitter Academic Research still not support Japanese?
Off topic, I was using Standard API version 1.1 to get tweets, but does Academic Account work with API v1.1?

Related

Azure Face Recognition gives "Attribute 'qualityForRecognition' is only supported for recognition_03 and recognition_04." error

I'm following the official MS Azure quickstart guide (https://learn.microsoft.com/en-gb/azure/cognitive-services/face/quickstarts/client-libraries?tabs=visual-studio&pivots=programming-language-rest-api), specifically the "Get face attributes" part and when replicating provided cURL examples in Postman, I'm getting the following error:
{
"error": {
"code": "BadArgument",
"message": "Attribute 'qualityForRecognition' is only supported for recognition_03 and recognition_04."
}
}
Any ideas? It seems like they've updated their API without updating documentation, which is something I wouldn've expected from a corp like Microsoft, but it's the only thing I can think of why it wouldn't be working. For reference, here's a screenshot of my Postman request.
As per documentation:
To extract face attributes, call the Detect API again, but set detectionModel to detection_01. Add the returnFaceAttributes query parameter as well.
Detect with stream example:
POST {Endpoint}/face/v1.0/detect?overload=stream&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise&recognitionModel=recognition_01&returnRecognitionModel=True&detectionModel=detection_01
Ocp-Apim-Subscription-Key: {API key}
returnFaceAttributes: Analyze and return the one or more specified face attributes in the comma-separated string like "returnFaceAttributes=age,gender".
Note: detection_01 supports age, gender, headPose, smile, facialHair, glasses, emotion, hair, makeup, occlusion, accessories, blur, exposure, noise, and qualityForRecognition While detection_02 does not support any attributes and detection_03 only supports mask and qualityForRecognition. qualityForRecognition is only supported when the 'recognitionModel' is specified as 'recognition_03' or 'recognition_04'.
As per Add QualityForRecognition in Face how-to samples, detection_01 is used with recognition_04
var faces3 = await faceClient.Face.DetectWithUrlAsync(url: imageUrl, returnFaceId: true, returnFaceAttributes: requiredFaceAttributes, detectionModel: DetectionModel.Detection01, recognitionModel: RecognitionModel.Recognition04);
You can also refer to Add qualityForRecognition attribute to Face Detection

Can I access a users' description (bio) directly through Tweepy?

I just started tinkering with Tweepy to see the extent of what's possible, and I'm wondering if I can grab a user's description (the short bio on their profile, under the handle) directly. I know the description can be accessed by using a workaround like this:
api = tweepy.API(auth)
pastrytweet = api.search('pastries')
for twit in pastrytweet:
print(twit)
This gives us an output that is a list (not in the Python sense) of Status objects, each of which contains a ton of information, eg:
Status(_api=<tweepy.api.API object at 0x038F6EF8>, _json={'created_at': 'XXXXXXXXXXX', 'id': XXXXXXXXXXXX, 'id_str': 'XXXXXXXXXXX', 'text': 'RT #XXXXXXXXXXX XXXXXX pastries XXXXXX', 'description': 'XXXXXXXXX')
I'm trying to access this "description" parameter seen here at the end directly, but any attempt I make returns a "AttributeError: 'Status' object has no attribute 'description'".
So if I wanted, say, to search for a term and grab the bio of a user that published a tweet with that term for some reason, how would I proceed? Or even to search people's bios directly? Is it even possible? I read the Tweepy documentation and I didn't really find an answer.
Each status object return by api.search has an attribute user and under user you'll find the description. The following code should help:
api = tweepy.API(auth)
pastrytweet = api.search('pastries')
for twit in pastrytweet:
print(twit.user.description)

twitter premium Api buid a search query with colon

I have a twitter premium API enabled and i am trying to get twitter data from a request query
search query rules
few words are in twitter body or in hashtags
language japanese
skip retweets
within date range
and some default parameters
I don't use any twitter API client library,I have created own small library to authentication and get the results.This issue with the search query because i am getting twitter data for other queries as expected.
query i have tried
{ "query":"lang:ja(-is:retweet((Reゼロ OR Re:ゼロ) OR (#Reゼロ OR #Re:ゼロ) ))",
"maxResult":500,
"fromDate":somedate,
"toDate":somedate
}
response is a error saying
There were errors processing your request:missing EOF at '(' (at
position 8)
I tried these methods,did't work.
"lang:ja(-is:retweet((Reゼロ OR "/Re:ゼロ/") OR (#Reゼロ OR "/#Re:ゼロ/") ))"
"lang:ja(-is:retweet((Reゼロ OR 'Re:ゼロ') OR (#Reゼロ OR '#Re:ゼロ') ))"
as far as i understand colon between word makes the error ex (Re:ゼロ),because if i remove colon it is return the data for query matching. I think colon makes complicated with twitter search operators like is:retweet.
these are some links i have followed
https://developer.twitter.com/en/docs/tweets/search/guides/premium-operators
https://developer.twitter.com/en/docs/tutorials/translating-plain-language-to-pt-rules
how to solve this?

How do I encode the names of Microsoft group and teams names to include them in an API call URL?

If I have an Office 365 Group/Microsoft Team with the ID "testteam#example.onmicrosoft.com", and I want to query it using one of the beta APIs such as this one, I need to query a URL such as https://graph.microsoft.com/beta/groups/{id}/threads. However, I am stuck on encoding the team name. https://graph.microsoft.com/beta/groups/testteam#example.onmicrosoft.com/threads, https://graph.microsoft.com/beta/groups/testteam#example%2Eonmicrosoft%2E/threads, and https://graph.microsoft.com/beta/groups/testteam#example/threads, https://graph.microsoft.com/beta/groups/"testteam#example"/threads, and https://graph.microsoft.com/beta/groups/"testteam#example.onmicrosoft.com"/threads all return the following error
"error": {
"code": "Request_BadRequest",
"message": "Invalid object identifier 'whatever_I_entered'."
As far as I understand it's just regular URL Encode. For example in JS you may use function encodeURIComponent(str). If you want to try use online URL encoder. For example encoded version of testteam#example.onmicrosoft.com will looks like testteam%40example.onmicrosoft.com and your graph request would be https://graph.microsoft.com/beta/groups/testteam%40example.onmicrosoft.com/threads
EDIT:
In the request you need to use Id of the group. For example: Get Group request may looks like ... and the group id is c28c1cc9-e1ab-4c4d-98d1-d8fdf128b60f
https://graph.microsoft.com/v1,0/groups/c28c1cc9-e1ab-4c4d-98d1-d8fdf128b60f?$select=description,allowExternalSenders

Does amazon provide an API for returning product information for a search term?

If you search on amazon for, say, "Don Quixote Spanish/English" you will find a number of matches or near-matches at http://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=Don%20Quixote%20Spanish%2FEnglish
You can then select any of them, and the URL will contain a designator (ASIN) for the product. For example, if you select a particular item in the result set, its URL might be:
http://www.amazon.com/Don-Quixote-Spanish-English-Complete-ebook/dp/B00JQRGICM/ref=sr_1_4?ie=UTF8&qid=1405527063&sr=8-4&keywords=Don+Quixote+Spanish%2FEnglish
The key piece of data here is the ASIN ("B00JQRGICM"); if you google using that alone, it will find many places where that product is referenced on the Internet.
My question is, does amazon provide an API whereby you can pass a search phrase (such as "Don Quixote Spanish/English") that will return to you an array of ASINs and other relevant data ("B00JQRGICM" and others)?
For example, I would like to call it something like this:
api/Books?SearchStr=Don Quixote Spanish/English
...and get back json such as:
{
Title: "Don Quixote in Spanish and English: Complete (Vol I & Vol II)"
Price: 16.15
ASIN: "B00JQRGICM"
Image: "http://ecx.images-amazon.com/images/I/519dhx-MSOL._SL160_.jpg"
}
. . .
If there is such an API, has anybody here got experience in using it/sample code?
Yes. You can search Amazon and get an XML response with the ASINs using the ListMatchingProducts operation of the MWS Products API.
Here's the documentation with a sample request & response:
http://docs.developer.amazonservices.com/en_US/products/Products_ListMatchingProducts.html
An easy way to test this is using the MWS Scratchpad: https://mws.amazonservices.com/scratchpad/index.html

Resources