如何使用 unity3d WWW 从 foursquare 发出请求

How to make a request from foursquare with unity3d WWW

首先,可能吗?我认为这是新的 unity 5。 我想通过 WWW 从 foursquare 发出请求。

这看起来很简单。您在 link 上有一个 GET 请求的示例:

https://api.foursquare.com/v2/venues/search?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&v=20130815&ll=40.7,-74&query=sushi

让我们将其转化为代码:

string CLIENT_ID = "CLIENT_ID";
string CLIENT_SECRET = "CLIENT_SECRET";
string v = "20130815";
string ll = "40.7,-74";
string query = "sushi";

string url = "https://api.foursquare.com/v2/venues/search?";
url += "client_id=" + CLIENT_ID + "&";
url += "CLIENT_SECRET=" + CLIENT_SECRET + "&";
url += "v=" + v + "&";
url += "ll=" + ll + "&";
url += "query=" + query;

现在,发送到服务器:

WWW connection = new WWW(url);
yield return connection;

if (connection.error != null)
{
    Debug.Log("Server-side error: " + connection.error);

}
else
{
    Debug.Log(connection.text);
}

您必须将 CLIENT_IDCLIENT_SECRET 替换为您自己的值。