开发者

SXAPI API Initialization error

I thought it is related To Meta but it is a programming question any way.

I was trying to practice Stackoverflow Api as a test case, I have tried using SXAPI (stack Overflow Version 4).

When I try to run simple program to fetch some user info, like

protected void Page_Load(object sender, EventArgs e)
        {           
            User user = StackExchangeApi.User.GetUserWithId(175216, StackExchangeApi.StackExchangeSite.StackOverflow);            
            Response.Write(user.Name + " has asked " + user.Questions.Count + " questions");           
            user.Clear(); 
        }

I 开发者_开发百科initially got this error

Call SXAPI.Initialize(...) before using SXAPI

Line 155:        {
Line 156:            if (UserAgent == null || !SXAPI.Initialized)
Line 157:                throw new NotInitializedException();
Line 158:
Line 159:            TimeSpan diff;

got it fixed using this peice of code:

SXAPI.Initialize("SoApiTest", new Uri("http://localhost:6832/Default.aspx"));

I cannot fingd this information any where as, why do we need to initialize the API, Is it the same case with all API's. Why addding a reference (.dll) is not enough like other applications ?


Isn't the answer, because it does? That's the way they designed the api. Its not the same with all APIs, some will require it some won't.

I imagine it gives them the ability to do some set up on their side before the api calls are used, although that's just stabbing in the dark...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜