Get user blogs array?

Feb 20, 2010 at 9:46 PM

Im not really sure how to use the getUserBlogs function propely.

Right now Im running this code:

 

        [XmlRpcMethod("blogger.getUsersBlogs")]
        public UserBlog[] getUsersBlogs(string appKey, string username, string password)
        {
            #region MSWLWgetUsersBlogs
            UserBlog returnMe;

            //TODO: please complete this code!
            //NOTE: user credentials are not checked here because
            //      user's blog list is retrieved using username 
            //      and password as DB filters. Feel free to use 
            //      checkUser( ) method.
            returnMe.blogid = "1";
            returnMe.blogName = "First blog";
            returnMe.url = "www.test.com";

            //throw new XmlRpcFaultException(0, "");
            return new UserBlog[] { returnMe};
            #endregion
        }

But as you can see this is only listing one blog.

How do I use the UserBlog[] array to send for example two different blogs with information to WLW?

Coordinator
Feb 20, 2010 at 9:57 PM

hi,

you can use List<UserBlog> blogList = new .... 

bloglist.add(new UserBlog());  //or create user blog separately in struct value.

you can use as mayn adds you want (or how many your user has)

in the return you simply return your list (not sure but maybe you should call something like this: bloglist.ToArray())

Feb 20, 2010 at 10:12 PM

Once again, thanks for you fast replies Boris.

But im sorry i didn't really get it with "List<UserBlog> blogList = new ...." or "bloglist.add(new UserBlog());  //or create user blog separately in struct value.".

Can you please post it as a code example? 

Also, the end line in the code is:

 

return new UserBlog[] { returnMe };

But how do I set "returnMe" to be an array with the blogs?

 

Feb 20, 2010 at 11:01 PM

I guess the "get-category-function" work the same way with the array so maybe I can use something like this I just came up with:

 

            Category[] returnMe = new Category[3];
            
            returnMe[1].categoryid = "1";
            returnMe[1].title = "1";

            returnMe[2].categoryid = "2";
            returnMe[2].title = "2";

            returnMe[3].categoryid = "3";
            returnMe[3].title = "3";
            return new Category[] { returnMe[1], returnMe[2], returnMe[3] };

This does indeed return three different categories but what if I want to return the categories in ONE array like:

 

	    return new Category[] { returnMe };

How do I manage this? I need some way to return the categories dynamicly since im loading them from a database.

Coordinator
Feb 21, 2010 at 8:49 AM
Here is my userblog[] method:
[XmlRpcMethod("blogger.getUsersBlogs")]
public UserBlog[] getUsersBlogs(string appKey, string username, string password)
{
#region BTgetUsersBlogs

List<UserBlog> returnMeList = new List<UserBlog>();
UserBlog returnMe;
SQLveza = SQLnaredba.Connection;
SQLveza.Open();
SQLnaredba.Parameters.Clear();
SQLnaredba.CommandText = "select userID, blogTitle from users where username = @user AND password = @pass;";
SQLnaredba.Parameters.AddWithValue("@user", username);
SQLnaredba.Parameters.AddWithValue("@pass", password);
SqlDataReader SQLcitac = SQLnaredba.ExecuteReader();
if (SQLcitac.HasRows)
{
while (SQLcitac.Read())
{
returnMe = new UserBlog();
returnMe.blogid = SQLcitac[0].ToString();
returnMe.blogName = SQLcitac[1].ToString();
returnMe.url = Metode.WebSiteRootURL + "user.aspx?userID=" + returnMe.blogid;
returnMeList.Add(returnMe);
}
}
else
{
SQLcitac.Close();
SQLveza.Close();
throw new XmlRpcFaultException(0, "fault username and password");
}
SQLcitac.Close();
SQLveza.Close();
return returnMeList.ToArray();
#endregion
}
nyqa wrote:

Once again, thanks for you fast replies Boris.

But im sorry i didn't really get it with "List<UserBlog> blogList = new ...." or "bloglist.add(new UserBlog());  //or create user blog separately in struct value.".

Can you please post it as a code example? 

Also, the end line in the code is:

 

return new UserBlog[] { returnMe };

But how do I set "returnMe" to be an array with the blogs?

 

 

Coordinator
Feb 21, 2010 at 8:51 AM
did you try this: return returnMe;
nyqa wrote:

I guess the "get-category-function" work the same way with the array so maybe I can use something like this I just came up with:

 

            Category[] returnMe = new Category[3];
            
            returnMe[1].categoryid = "1";
            returnMe[1].title = "1";

            returnMe[2].categoryid = "2";
            returnMe[2].title = "2";

            returnMe[3].categoryid = "3";
            returnMe[3].title = "3";
            return new Category[] { returnMe[1], returnMe[2], returnMe[3] };

This does indeed return three different categories but what if I want to return the categories in ONE array like:

 

	    return new Category[] { returnMe };

How do I manage this? I need some way to return the categories dynamicly since im loading them from a database.

 

Feb 22, 2010 at 12:08 AM

Yeah I did but that didn't work. Just gave me an error.

I got all my categories saved in a database so I need to loop them through and create and array from them.

Any idea how to post the return?

Feb 22, 2010 at 12:15 AM

This code didn't give me any error:

 

        public Category[] getCategories(string blogid, string username, string password)
        {
            #region MSWLWgetCategories
            Category[] returnMe;
 
            return returnMe;
            #endregion
        }

But how do I now add multible categoires to the returnMe variable?

 

Coordinator
Feb 22, 2010 at 3:18 PM

what was the error?

to return list of categories please refer to above UserBlog[] method, where you can see how to return array of n elements.