I want to know why GET https://mastodon.example/api/v1/timelines/list/:list_id HTTP/1.1
on the reference site cannot get a timeline for the list
Communication is successful because other webclient systems are successful.
Experiment by changing the URL
to various shapes like in the comment section
Other webclient
communication operations are successful, so agents and others are successful.
The output of the command prompt may not be OK with StatusCode, so I am checking the value.
list_id
is correct as it is on the web browser
The reference code
is written by myself and works fine, but I am doing exactly the same thing, so I should have been able to get it, so I cannot get it.
View list timeline: https://docs.joinmastodon.org/methods/timelines/
10819
mstdn.jp
list_id=10819&Authorization=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
NotFound
/*##################################################################################################################
* List Timeline Retrieval
###################################################################################################################*/
public async Task<List<JsonData.Post>?>getListTimeLine_Asnyc(string listID,string?max_id,string?since_id,string?min_id,string?limit)
{
// var response = wait client.GetAsync("https://"+instance+"/api/v1/timelines/list/:"+Method_Parameter.GetListTimeLine(listID,token,null,null,null).ReadAsStringAsync().RoundAsstringAsync();
// var response = wait client.GetAsync("https://"+instance+"/api/v1/timelines/list/:list_id?"+Method_Parameter.GetListTimeLine(listID,token,null,null,null,null).ReadAsstringAsync(RoundAsync;)
// var response = wait client.GetAsync("https://"+instance+"/api/v1/timelines/list/"+Method_Parameter.GetListTimeLine(listID,token,null,null,null).ReadAsStringAsync().Result);
// var response = wait client.GetAsync("https://"+instance+"/api/v1/timelines/list/?"+Method_Parameter.GetListTimeLine(listID,token,null,null,null).ReadAsStringAsync().RoundAsstringAsync();
var response = wait client.GetAsync("https://"+instance+"/api/v1/timelines/list/"+Method_Parameter.GetListTimeLine(listID,token,null,null,null).ReadAsStringAsync().Result);
var response = wait client.GetAsync("https://"+instance+"/api/v1/timelines/list/:list_id"+Method_Parameter.GetListTimeLine(listID,token,null,null,null,null).ReadAsStringAsync(Rult);
if (response.StatusCode==HttpStatusCode.OK)
{
var notice = wait response.Content.ReadFromJsonAsync<List<JsonData.Post>>();
List<JsonData.Post>list=new List<JsonData.Post>();
foreach (JsonData.Post n in notice)
{
list.Add(n);
}
return list;
}
else
{
Console.WriteLine(listID);
Console.WriteLine(instance);
Console.WriteLine(Method_Parameter.GetListTimeLine(listID,token,null,null,null).ReadAsStringAsync().Result);
Console.WriteLine(response.StatusCode);
return null;
}
return null;
}
/*##################################################################################################################
* List Timeline Retrieval
###################################################################################################################*/
static publicFormUrlEncodedContentGetListTimeLine(string listID, string token, string?max_id, string?since_id, string?min_id, string?limit)
{
var parameter = new Dictionary <string, string>();
parameter.Add("list_id", listID);
// parameter.Add(":list_id", listID);
parameter.Add("Authorization", token);
if(max_id!=null)
{
parameter.Add("max_id", max_id);
}
if(since_id!=null)
{
parameter.Add("since_id", since_id);
}
if(min_id!=null)
{
parameter.Add("min_id", min_id);
}
if(limit!=null)
{
parameter.Add("limit", limit);
}
return new FormUrlEncodedContent (parameter);
}
/*##################################################################################################################
* Get Notification List
###################################################################################################################*/
public async Task<List<Notice>?>getNotics_Asnyc()
{
var response = wait client.GetAsync("https://"+instance+"/api/v1/notifications?"+Method_Parameter.GetNotics(token, null, null, null, null).ReadAsStringAsync().Result);
if (response.StatusCode==HttpStatusCode.OK)
{
var notice = wait response.Content.ReadFromJsonAsync<List<JsonData.Notice>>();
List<Notice>list=new List<Notice>();;
foreach (JsonData.Notice not in notice)
{
Notice nn = new Notice(n);
list.Add (new notice(n));
}
return list;
}
else
{
Console.WriteLine("getList_Async()"+response.StatusCode);
return null;
}
return null;
}
To have API access, you must be able to understand the contents of reference and build your own URL to access.The cause is a lack of understanding of the reference, so no matter how much you fix the code, it will not be resolved because it will never reach the correct URL.
How to use the API for Mastodon is written in Getting started with the API, but it is written for people who know the typical REST API.It contains details that may differ from the typical REST API (most of which are unique to Ruby on Rails where the Mastdon was created).If you don't know Ruby on Rails, you need to read it.Then check the API reference side and think about what URL you should access.
First of all, do you know the components of the URL?If you don't know, I can't understand it even if I read the future.In that case, please re-study with books.
The URL is largely divided into the following elements:(In addition to this, there is a hash, but I will omit it because I will not deal with it this time.)
If you use this to represent the URL, it is in the form [Scheme]://[Host][Path]?[Query]
.So, what do these look like in the reference?GET https://mastodon.example/api/v1/timelines/list/:list_id HTTP/1.1
, so
https
mastodon.example.com
/api/v1/timelines/list/:list_id
No, it's not.
First, the host is not an example, but an actual server.There are many different servers in Mastdon, so it depends on the server you are actually using.As you may know, for a single service like Twitter, the host may remain the same.
Next, the path is that this reference is written to some extent for those who know the REST API.You can see :list_id
in the path, but you cannot write :
exactly in the path. If you are not familiar with the REST API, you must realize that this cannot be a path string as it is.In , :list_id
is the parameter メーターpath parameters/Path parameters と contained in the path.So, I immediately wrote what the value will be in Path parameters.It means that the ID of the list is included as a string.What I mean is, if the ID in the list is 42, the path will be /api/v1/timelines/list/42
.
Finally, there was no query starting with GET
.However, it doesn't mean you can't query it.There is a query that you can add to Query parameters.For example, if you want limit
to be 30, you can add limit=30
and a query.
Now, let's take a look at what happens when the list has up to 30 IDs for 42.Leave the host as it is.
https
mastodon.example.com
/api/v1/timelines/list/42
limit=30
The URL is as follows:
https://mastodon.example.com/api/v1/timelines/list/42?limit=30
You must access these URLs.First, generate a string that will be the URL and check if it has the expected value in Console.WriteLine()
.
Finally, the header should contain an authorization token (Authorization
), but if anything else is available, it probably is.
I already have a library of C#, so I think it would be faster to re-invent the wheel myself.If it's for studying REST API, I think Qiita API and Japanese explanations are easier to do at first.
I overlooked that the path parameters, query parameters, and headers are different.As a result, I was able to get the following URL as per the reference site.
var response=wait client.GetAsync("https://"+instance+"/api/v1/timelines/list/"+listID);
© 2024 OneMinuteCode. All rights reserved.