配置此https://pipl.com/dev/接口时遇到问题
我在页面加载事件中有这段代码,但问题是,一旦我点击“在浏览器中查看页面”,它就会继续加载页面。
protected void Page_Load(object sender, EventArgs e)
{
RunAsync().Wait();
}
static async Task RunAsync()
{
SearchAPIRequest req = new SearchAPIRequest(email: "clark.kent@example.com");
SearchAPIResponse resp = await req.SendAsync();
Console.Out.WriteLine(resp.Image.GetThumbnailUrl(200, 100, true, true));
Console.Out.WriteLine(resp.Name);
Console.Out.WriteLine(resp.Education);
Console.Out.WriteLine(resp.Username);
Console.Out.WriteLine(resp.Address);
var jobs = resp.Person.Jobs.Select(j => j.ToString());
Console.Out.WriteLine(String.Join(", ", jobs));
Console.Out.WriteLine();
var relationships = resp.Person.Relationships.Select(r => r.Names[0]);
Console.Out.WriteLine(String.Join(", ", relationships));
Console.Out.WriteLine();
}我是不是遗漏了一些代码?或者其他任何事情..。请指点一下。
PS:我已经用"PM> Install-Package piplclient“安装了他们的软件包
发布于 2015-09-16 16:32:19
ASPX页面需要有"Async=true“才能使用异步方法。以下是一个后端C#文件示例:
using Pipl.APIs.Search;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : Page
{
protected async void Page_Load(object sender, EventArgs e)
{
SearchAPIRequest request = new SearchAPIRequest(email: "clark.kent@example.com");
try
{
var response = await request.SendAsync();
Response.Write(response.Name.ToString());
}
catch (SearchAPIError ex)
{
Console.Out.WriteLine(e.ToString());
}
catch (IOException ex)
{
Console.Out.WriteLine(e.ToString());
}
}
}
}https://stackoverflow.com/questions/31508213
复制相似问题