無料で登録せずに、名前の翻訳とリンクがある国、地域、居住地のデータベースを取得しますか? 本物です!
大きな野心を持った小さなスタートアッププロジェクトを開発するとき、少なくとも最も一般的な言語(英語、ロシア語、スペイン語、ドイツ語など)に名前を翻訳した国、地域、都市のデータベースが必要になりました。 既成のソリューションが見つからなかったため、必要なデータを解析できるソースを探し始めました。 有名なソーシャルネットワークがすぐに思い浮かびました。 この記事ではすでにVKontakteからのデータの受信について説明しましたが、VKontakte APIのドキュメントをざっと調べて、地理データを取得するためのオープンで文書化された方法を見つけてうれしく思いました 。
database.getCountries-国のリストを返します。
database.getRegions-リージョンのリストを返します。
database.getCities-集落のリストを返します。
database.getCountriesById-識別子で国情報を返します
database.getCitiesById-識別子で都市に関する情報を返します。
これらは私たちにとって関心のある主な方法であり、承認とトークンの使用も必要ありません。 その他のメソッドは、ドキュメントのセクションにあります。
国のリストを取得する方法にアクセスするためのURLの例を以下に示します(httpsプロトコルを使用して同様の手順が発生します)。
http://api.vk.com/method/database.getCountries?v=5.5&need_all=1&count=10
結果を見る
{"response":{"count":234,"items":[{"id":19,"title":""},{"id":20,"title":""},{"id":5,"title":""},{"id":21,"title":""},{"id":22,"title":""},{"id":23,"title":" "},{"id":24,"title":""},{"id":25,"title":""},{"id":26,"title":""},{"id":27,"title":" "}]}}
パラメータ:
v -APIのバージョンを示します。 異なるバージョンでは、JSON構造は異なります。 たとえば、バージョン5.0以降、カウント値が追加されました。これには、選択範囲内の要素の総数が含まれ、offsetパラメーターと併用すると、すべての値を取得するのに役立ちます。 デフォルトでは、データは古いバージョンで返されます(明らかに古いアプリケーションとの互換性のため)。
count-メソッドによって返される値の最大数。 設定できるパラメーターの最大値は1000要素です。 各方法の最小値とデフォルト値は異なる場合があるため、ドキュメントを参照してください。
need_all-オプションのパラメータ。デフォルト値は「0」で、小さな地域/国/集落を選択しないことを示します
公式ドキュメントにあるように、各関数の残りのパラメーターをペイントしても意味がありません。非公式の機能に移りましょう。
さまざまな言語の国のリストを取得する
<?php $lang = 0; // russian $headerOptions = array( 'http' => array( 'method' => "GET", 'header' => "Accept-language: en\r\n" . "Cookie: remixlang=$lang\r\n" ) ); $methodUrl = 'http://api.vk.com/method/database.getCountries?v=5.5&need_all=1&count=1000'; $streamContext = stream_context_create($headerOptions); $json = file_get_contents($methodUrl, false, $streamContext); $arr = json_decode($json, true); echo 'Total countries count: ' . $arr['response']['count'] . ' loaded: ' . count($arr['response']['items']); print_r($arr['response']['items']);
メソッドがcookie remixlangパラメーターで指定された言語でデータを返そうとすることは注目に値します。 したがって、必要な言語の数値を置き換えて、翻訳があれば必要な言語のデータを取得します。 すべての国は、ソーシャルネットワークで利用可能なすべての言語に翻訳されています。 地域および都市の場合:翻訳がない場合(小さな集落、小さな国の地域)、この地域で人気のある言語、たとえば、アフリカ諸国、英語、CIS諸国-ロシア語で値を取得します。
言語識別子の短いリストは次のとおりです。
言語 | remixlangの価値 |
ロシア語 | 0 |
ウクライナ語 | 1 |
英語 | 3 |
スペイン語 | 4 |
ポルトガル語 | 12 |
ドイツ人 | 6 |
フランス語 | 16 |
イタリア人 | 7 |
さまざまな言語の地域のリストを取得する
country_idパラメーター(必須パラメーター)で指定された国の地域のリストを取得するメソッドにアクセスするためのURLの例:
http://api.vk.com/method/database.getRegions?v=5.5&need_all=1&offset=0&count=1000&country_id=
<?php $countryId = 1; // Russia $lang = 0; // russian $headerOptions = array( 'http' => array( 'method' => "GET", 'header' => "Accept-language: en\r\n" . // "Cookie: remixlang=$lang\r\n" ) ); $methodUrl = 'http://api.vk.com/method/database.getRegions?v=5.5&need_all=1&offset=0&count=1000&country_id=' . $countryId; $streamContext = stream_context_create($headerOptions); $json = file_get_contents($methodUrl, false, $streamContext); $arr = json_decode($json, true); echo 'Total regions count: ' . $arr['response']['count'] . ' loaded: ' . count($arr['response']['items']); print_r($arr['response']['items']);
メソッドと説明のパラメーターのリストは、ドキュメントに記載されています。 ただし、返されるJSONは空である可能性があります。つまり、 すべての国を地域に設定できるわけではないことに注意してください。この場合、都市のリストを受信するときに、region_idパラメーターを省略できます。
集落のリストを取得する
country_idパラメーター(必須パラメーター)およびregion_id地域(オプションのパラメーター)で指定された国の都市のリストを取得するメソッドにアクセスするためのURLの例:
http://api.vk.com/method/database.getCities?v=5.5&country_id=1®ion_id=1045244&offset=0&need_all=1&count=1000
<?php $regionId = 1045244; $countryId = 1; // Russia $lang = 0; $headerOptions = array( 'http' => array( 'method' => "GET", 'header' => "Accept-language: en\r\n" . "Cookie: remixlang=$lang\r\n" ) ); $methodUrl = 'http://api.vk.com/method/database.getCities?v=5.5&country_id=' . $countryId . '®ion_id=' . $regionId . '&offset=0&need_all=1&count=1000'; $streamContext = stream_context_create($headerOptions); $json = file_get_contents($methodUrl, false, $streamContext); $arr = json_decode($json, true); echo 'Total cities count: ' . $arr['response']['count'] . ' loaded: ' . count($arr['response']['items']); print_r($arr['response']['items']);
各地域の返されるデータには、次のパラメータも含まれる場合があります。
area-地区の名前(州など)
「1」に等しい重要 -大都市の指定、need_allパラメーターを使用する場合にのみ表示されます
注意! 一部の地域には、開拓地が含まれていない場合があります(または、それ自体が開拓地である可能性があります)
衝突
一部の受信値には、特殊文字、タグ(たとえば、
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
が含まれる場合があります
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813
<br>
).
Updated
cookie, . uh_zuh , lang ( lang=ru).
Updated 2
, lang .
Updated 3
, :
GitHub
SQL PostgreSql
Yandex Disk
Google Drive
SQL MySql
Yandex Disk
Google Drive
CSV
- (;), , (")
Yandex Disk
Google Drive
- (,), , (")
Yandex Disk
Google Drive
: , i, , , , , , , , , , , ,
234
3 721
2 246 813