HOW TO USE JOEBLOG WORDPRESS WRAPPER
In this tutorial I will show you how to use JoeBlogs WordPress Wrapper based on XML-RPC to auto post to WordPress from an C# Application and for beginners how to post to WordPress from c# .net. I will show you also how to add images with JoeBlogs and how to auto complete custom fields directly from your .Net (C# Examples) Application.
First of all you have to download latest version of wrapper from GitHubor Here the version which I have used on my example.
Now create a new C# application and let’s start.
source: howtofix.pro/how-to-use-joeblog-wordpress-wrapper-tutorial-with-examples/
1.ADDING DEPENDENCIES LIBS
UnRar downloaded files to
C:\Libs
directory for example.
Right-Click on
Project Name
from Solution Explorer >> Add
>> Reference...
Then Browse >> Click and Browse Button and Select
"CookComputing.XmlRpcV2.dll" "JoeBlogs.dll"
>> Add
Now the final step is to add this to your code:
using JoeBlogs;
And now we are ready to start using JoeBlogs XML-RPC Wrapper.
2.HOW TO USE JOEBLOGS:
This simple example code will help you to understand how to use JoeBlogs WordPress Wrapper:
1
2
3
4
5
6
7
8
9
10
11
12
13
| string username = "yourUserName" ; string password = "password" ; var wp = new WordPressWrapper(link + "/xmlrpc.php" , username, password); var post = new Post(); post.DateCreated = DateTime.Today.AddHours(0); post.Title = "Post Totle" ; post.Body = "HowToFix.pro Content Here - Test post" ; post.Tags = tags.Split( ',' ); // string tags = "tags1,tag2"; wp.NewPost(post, true ); |
Adding an image with JoeBlogs WordPress Wrapper:
1
2
3
| byte [] imageData = System.IO.File.ReadAllBytes( "pathToImage" ); var image = wp.NewMediaObject( new MediaObject { Bits = imageData, Name = "nameAfterUploading" }); string linkToImage = image.URL; //use this in your post |
Adding custom fields on JoeBlogs WordPress Wrapper:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| var cfs = new CustomField[] { new CustomField() { Key = "_aioseop_title" , Value = "AIO Title" }, new CustomField() { Key = "_aioseop_description" , Value = "AIO Description" }, new CustomField() { Key = "_aioseop_keywords" , Value = "AIO Tags" } }; //Use it in this way post.CustomFields = cfs; |
OK, but now where I can take from the
Key
value? From Database >> wp_postmeta Table.
If you want to complete All In One SEO Fields first you have to make sure that you have Unprotect Post Meta Fields because you are not able to modify protected meta with XML-RPC WordPress API.
3.WHOLE JOEBLOGS XML-RPC WORDPRESS WRAPPER EXAMPLE FUNCTION:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| private void postToWordpress( string title, string postContent, string tags, string aioTitle, string aioContent, string aioTags) { string link = this .maskedTextBox1.Text; string username = this .maskedTextBox2.Text; string password = this .maskedTextBox3.Text; // webBrowser1.Navigate(url); -- IE -- pass this shit var wp = new WordPressWrapper(link + "/xmlrpc.php" /*fuck this shit*/ , username, password); /* if you want to upload an image byte[] imageData = System.IO.File.ReadAllBytes("image.png"); var image = wp.NewMediaObject(new MediaObject { Bits = imageData, Name = "image" }); str = str.Replace("[SCREENSHOT1]", image.URL); */ var post = new Post(); post.DateCreated = DateTime.Today.AddHours(0); post.Title = title; post.Body = postContent; post.Tags = tags.Split( ',' ); if (checkBox1.Checked == true ) //if AIO is enabled { ////Let distraction come --- custom fields/// var cfs = new CustomField[] { new CustomField() { Key = "_aioseop_title" , Value = aioTitle }, new CustomField() { Key = "_aioseop_description" , Value = aioContent }, new CustomField() { Key = "_aioseop_keywords" , Value = aioTags } }; post.CustomFields = cfs; ////after ..zzZZzz. hours..zzZZzzZzzzzZZZ..5:00 PM distraction enddddddddd..zZZzzZz(0_o)zZzzzZZZz */ } wp.NewPost(post, false ); // save post link to a text file <img draggable="false" class="emoji" alt="" src="https://s.w.org/images/core/emoji/72x72/1f642.png"> if (System.IO.File.Exists( "links.txt" )) { string buff = System.IO.File.ReadAllText( "links.txt" ); buff = buff + System.Environment.NewLine + wp.GetPost(post.PostID).ToString(); System.IO.File.WriteAllText( "links.txt" , buff); } MessageBox.Show( "Posted :)" ); } |
4.FULL APPLICATION EXAMPLE:
I have made a little Application which is using JoeBlogs WordPress Wrapper to post to a WordPress Blog:
Download whole project here: JoeBlogsWordpressWrapperTests.rar
ConversionConversion EmoticonEmoticon