Is there any way I can access the thumbnail picture of any wikipedia page by using an API? I mean the image on the top right side in box. Is there any APIs for that?
Answers
Don't try to use the raw API, instead use a client wrapper. Here's a long list to choose from, all for PHP:
http://en.wikipedia.org/wiki/Wikipedia:PHP_bot_framework_table
Ok, I got the Problem: it must impersonate the User account which have the privilege to access the API scope that I mentioned in program.
So some additional codes must be added as following:
$email = '<email account which could access that api>';
$scope = 'https://www.googleapis.com/auth/cloud-platform';
$apiKey = '<my api key>';
$oAuthId = '<OAuth ID>';
$serviceAcc = '<service account id>@developer.gserviceaccount.com';
$keyFileLocation = $_SERVER['DOCUMENT_ROOT']. "/<p12 file>";
$bucketId = '<my bucket id>';
$list = array();
$client = new Google_Client();
$client->setApplicationName("gp-api");
$client->setDeveloperKey($apiKey);
$cred = new Google_Auth_AssertionCredentials (
$serviceAcc,
array($scope),
file_get_contents($keyFileLocation),
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
$email
);
Woooooyaaaaa, another problem solved! time to move up for next problem.
It's creating the event in the calendar owned by the service account, if you want to manage it, you have to share the calendar with yourself (!):
$scope = new Google_AclRuleScope();
$scope->setType('user');
$scope->setValue('YOUR-EMAIL-HERE');
$rule = new Google_AclRule();
$rule->setRole('owner');
$rule->setScope($scope);
$result = $service->acl->insert('primary', $rule);
Reference: Who owns calendars created by service account via Google Calendar API and how can they be shared?
PS: there's a new version of the PHP client library.
Wikipedia has an extensive API, which can provide language links information among others. In this particular case, you're looking for api.php?action=query&prop=langlinks&titles=...
. See here for example.
http://en.wikipedia.org/w/api.php
Look at
prop=images
.It returns an array of image filenames that are used in the parsed page. You then have the option of making another API call to find out the full image URL, e.g.:
action=query&titles=Image:INSERT_EXAMPLE_FILE_NAME_HERE.jpg&prop=imageinfo&iiprop=url
or to calculate the URL via the filename's hash.
Unfortunately, while the array of images returned by
prop=images
is in the order they are found on the page, the first can not be guaranteed to be the image in the info box because sometimes a page will include an image before the infobox (most of the time icons for metadata about the page: e.g. "this article is locked").Searching the array of images for the first image that includes the page title is probably the best guess for the infobox image.