Get Data info from a certain page- MediaWiki API - mediawiki

I'm very new to the api system and i was wondering how to get data from a certain page. So my link is:
https://nookipedia.com/w/api.php
but i want to get my api from this page:
https://nookipedia.com/wiki/Bugs/Animal_Crossing:_New_Leaf
but when i try this:
https://nookipedia.com/wiki/Bugs/Animal_Crossing:_New_Leaf/w/api.php
the link doesn't work and gives me this error:
Error 404: Not found
The requested page or file could not be found on our server. It may have been moved or deleted.
How would i get that certain page?

I suggest you play around with the API sandbox on Wikipedia to see how queries are built. You will still need to read the actual API documentation to get useful information...
Basically, you want to pass the title(s) as a parameter to api.php, like so:
https://nookipedia.com/w/api.php?titles=Bugs/Animal_Crossing:_New_Leaf
However, this will still get you no information by itself; you need to know what data you want exactly, and use the correct API module with the appropriate parameters. For example, to get all the categories of a page:
https://nookipedia.com/w/api.php?action=query&titles=Bugs/Animal_Crossing:_New_Leaf&prop=categories
For this specific example, you can see the documentation for the Query API and the Categories property:
API:Query
API:Categories

Related

Instagram Analyze via API or something else

for a master thesis I need to analyze several Instagram profiles with more than 1000 posts each.
I need a list of the following things:
Post Type (Image, Multi Image, Video)
description
Likes
Comments (count)
Is there a way to do this with the Instagram Api or do you have another idea how this can work?
Thank you so much
Torben
Sorry. Not easily possible. Facebook has disabled this feature. What parts of this that still work will likely be disabled. You could try to scrape the profiles yourself from the public HTML Instagram webpages.
Using the developer console in Google Chrome and analyzing the network traffic I found the following URL that might be able to do some of what you want. Looks like calling the /graphql/query/ URL with a JSON object as a query parameter labeled: variables, along with a hash of some kind of that object. Not sure if you can call it on your own, but I've had success with other embedded URLs like this. The ID is the users ID which you can get from the HTML as well.
I hope it helps somehow.
https://www.instagram.com/graphql/query/?query_hash=76d9c5f9c2d88aa251ece9ea61fdc570&variables=%7B%22id%22%3A%225466275%22%2C%22first%22%3A12%2C%22after%22%3A%22AQCqBkaT0gZcgV1z9nfTgM3saTJi3cDRQoQy2YM4SdWNWyo3kdMTfCzWvuGcGRI9e1WpAIquMMG9jeuuXSe0TSMiQMPIL1ZmVimTMQ0dfrD_9Q%22%7D
Decoded that is:
https://www.instagram.com/graphql/query/?query_hash=76d9c5f9c2d88aa251ece9ea61fdc570&variables={"id":"5466275","first":12,"after":"AQCNhv_lxGd-nHBBaZb5kk3J4N-n058NgyCiWDnJ10rLc2V-YrVUvGsiuXr4NsMQ4QDzOLdjbTIVqoMpspJ69r-0s-PzOceis9J25o8P2BcjdA"}

How to find how many json endpoints an api has

I’m in the middle of making an Express app. It’s just a learning project.
I’m getting some info from an Anime api called jikan.me, it provides info about different Anime series like a picture url and synopsis.
For example one is at https://api.jikan.me/anime/16 .
Now, the jikan api might have a json endpoint at anime/1 but there's nothing at anime/2.
I want to find a list of all the numbers (https://api.jikan.me/anime/[numbers]) that actually contain endpoints.
I've tried simply going to https://api.jikan.me/anime but it returns error: No ID/Path Given.
I'm expecting there is likely no absolute answer to this problem but that I might learn something about server-side code along the way.
Where would I begin to look to find this info?
This is a bit late but, Jikan is an unofficial REST API for MyAnimeList. The IDs are respective to the IDs on MAL. For example; https://myanimelist.net/anime/1 can be parsed through https://api.jikan.moe/anime/1 but the ID 2 does not exist on MAL. It's a 404, hence that error.
To initially get some IDs, you can try the search endpoint.
Furthermore, I'll be releasing REST 2.2 quite soon (this month) which will give you the ability to parse from pages like these and thus you'll get another endpoint that provides a handful of IDs to get their data from.
Source: I'm the developer of Jikan
If it's not in the documentation it's probably information not available to you... a REST api needs to be specifically configured to offer certain endpoints, that number at the end might just be an ID that's searched for in an internal database and there's no way for the application to know if there's gonna be something there; all they can do is return an error message for you to handle as is the case here.

Retrieving 'Likes' programmatically

I am doing an analysis of Credit Union social activity. I have some code that takes a link like this...
https://www.facebook.com/americanlakecu/likes
... and converts it to this...
http://graph.facebook.com/americanlakecu
..which enables me to grab 'Likes' and 'People Talking'. The problem is many institutions, particularly the smaller ones, seem to use a different format. Here's an example.
https://www.facebook.com/pages/EvergreenDIRECT-Credit-Union/276887662722?sk=likes
Anyone know how to convert the link above so I can use the api to render JASON in the same way as http://graph.facebook.com/americanlakecu ?
You need to reference the facebook id when hitting the graph for the other institutions. For americanlakecu, that id is americanlakecu. For Evergreen's case, try 276887662722. But for some reason, your "smaller" pages need an access token. I think the difference might be a simple matter of availability of data.
You can still get their data as I described above, but you need an api access token. For instance, following this link directly will show you nothing: http://developers.facebook.com/tools/explorer/?method=GET&path=276887662722 , but after you get there, if you fetch an access token, you will see all the info you need.
So, configure your implementation of the SDK to use an access token, and you ought to be able to continue using the handy graph method.

Contact API directly from URL in browser

I am trying to understand how POST and/or GET methods work in terms of the actual browser.
I am attempting to contact an API which requires API key, method you wish to use on their side, and an IP address at the minimum.
My original idea was to do something like this:
I feel like I'm on the right track, it does something and gets an error as opposed to telling me the page does not exist. I'm expecting either JSON or XML in response as the API supports both but instead I get this error:
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
Upon studying the documentation of the API more, I found something saying that methods are called using HTML form application/x-www-form-urlencoded and the resuource models are given as form elements.
I tried researching what that means to see what the problem was and found this site http://www.w3.org/TR/xforms11/ but I'm still unclear.
Ideas?
It seems to mean that the application is expecting a POST method but you're doing a request with a GET method (when you use the querystrings).
Since you can't just do browser requests using POST using the address bar, you may need to:
Construct a simple JS function that does a xmlhttprequest request using that method instead, and running it from the console;
Create a simple HTML page that automates the above process, allowing you do make POST calls;
Using CURL instead, which is a great tool for testing those kinds of requests.

Customizing json rendering for sling's userManager

I am trying to build my application's admin UI using sling's userManager REST interface, but I would like to customize the json rendering. For example, I would like the response of "Get group" to include the members only if the requestor is a member.
I started by adding libs/sling/group/json.esp but I don't understand how I can get hold of the default response and customize it. Even if I had to query and form the json from scratch, where can I find information about APIs available to get this data from JCR/Sling?
I found that I could use ResourceTraversor to dump the resource object in json form but using new Packages.org.apache.sling.servlets.get.impl.helpers.ResourceTraversor(-1, 10000, resource, true) in the esp throws up an error
There are a few things to note here.
First, you should avoid putting your code under the libs directory. Your app code should live under the apps directory. When attempting to resolve a servlet for a URI, Sling will check apps before it checks libs so if you need to completely override functionality delivered with Sling, you would place your code in apps.
Second, what is (probably, depending on how you have things setup) happening when you request http://localhost:8080/system/userManager/group/administrators.tidy.1.json is the request is being handled by Sling's default GET servlet, because it finds no other script or servlet which is applicable. For research purposes it might be worth looking at the code for the default get servlet, org.apache.sling.servlets.get.impl.DefaultGetServlet, to see what it's using to render JSON. If you need to handle the rendering of a user group in a manner different than what the default GET servlet is doing, then you would need to create a servlet which is listening for requests for resources of type sling/group. It would probably be ideal to create a servlet for this purpose and register it with OSGI. http://sling.apache.org/site/servlets.html provides the various properties you would need to set to ensure the servlet resolver finds your servlet. Your servlet then would handle the request and as such would have direct and easy access to the requested resource.
Third, the particular need you specified is that you do not want the group members to render unless the requesting user is a member of the group requested. This is more of an access control issue than a rendering issue. Sling and Jackrabbit, out of the box, make as few assumptions as possible concerning how you might want your application to be setup. That being the case, you need to establish the access controls that are applicable for your particular use case. The wiki post on Access Control in the Jackrabbit wiki ( http://wiki.apache.org/jackrabbit/AccessControl ) goes into this to an extent.
Using directions from Paul Michelotti's answer, I researched further and found a suitable solution to my problem.
Sling accepts request filters (javax.servlet.Filter) through SCR annotations like the one below
#SlingFilter(scope = SlingFilterScope.REQUEST, order = Integer.MIN_VALUE)
Every request is passed down to the filter before it is processed by the servlet. Using the resourceType, I was able to distinguish requests to group.1.json and group/mygroup.1.json. Since the filter also has access to the current user, I was able to decide to deny the request if it did not abide by my security model and return a 404 status code.
Please refer to this page for details on filters. You can also check out the sample project urlfilter for directions on usage.