首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在asp.net中使用pipl api

在asp.net中使用pipl api
EN

Stack Overflow用户
提问于 2015-07-20 10:53:13
回答 1查看 255关注 0票数 0

配置此https://pipl.com/dev/接口时遇到问题

我在页面加载事件中有这段代码,但问题是,一旦我点击“在浏览器中查看页面”,它就会继续加载页面。

代码语言:javascript
复制
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“安装了他们的软件包

EN

回答 1

Stack Overflow用户

发布于 2015-09-16 16:32:19

ASPX页面需要有"Async=true“才能使用异步方法。以下是一个后端C#文件示例:

代码语言:javascript
复制
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());

            }
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31508213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档