I am using JoeBlogs https://github.com/alexjamesbrown/JoeBlogs to handle stuff on some of my wordpress websites. I am having some problems with creating a new category and uploading a picture.
Here is my code for creating a new category:
var wpWrapper = new WordPressWrapper("http://192.168.1.2/xmlrpc.php", "admin", "admin");
wpWrapper.NewCategory("some description", 0, "cat1", "slug here");
I am getting the following error from CookComputing library:
XmlRpcServerException: Not Found
I get the same error for uploading a picture. I've tried 2 versions of uploading a picture with uploadfile and newmediaobject.
Here is what I've made with the newmediaobject:
var blog = new WordPressWrapper("http://192.168.1.2/wordpress", "admin", "admin");
byte[] imageData = System.IO.File.ReadAllBytes("desert.jpg");
var img = blog.NewMediaObject(new MediaObject { Bits = imageData, Name = "desert.jpg", Type = "image/jpeg" });
I am getting this error: Response from server does not contain valid XML
Here is my second try with uploadfile:
var blog = new WordPressWrapper("http://192.168.1.2/wordpress", "admin", "admin");
wpWrapper.UploadFile("desert.jpg", "desert.jpg", true,"image/jpeg");
I am getting the same error, with the invalid XML (just like the first try with mediaobject).
What do you guys suggest ?
I am open to other libraries that could help me achieve this.
Ok, so the problems look like they were REALLY SIMPLE.
The xmlrpc.php file for my wordpress is in this path
192.162.1.2/wordpress/xmlrpc.php
In the first part (create category), I forgot to add "wordpress" in the uri.
For the second part (upload image), I haven't forgot to add "wordpress" but I forgot to add "xmlrpc.php" at the end.
Stupid mistakes, but for those who encouter the same problems, check that out first.
Related
I am building a google document from Google docs API.
My doc is created from a template: copy the template in new location, replace texts, and replace images.
Everything is OK until I try to replace my images.
The images to put in the file are stored in a Google Drive folder.
So, I have 2 questions:
the first one is how to use replaceImage request with viewing URL of my image?
By using following code, I am facing a 400 error.
IDictionary<string, InlineObject> inlineObjects = doc.InlineObjects;
//Get the objet ID
string imageObjectId = inlineObjects.First().Value.ObjectId;
BatchUpdateDocumentRequest batchUpdateRequest = new BatchUpdateDocumentRequest {
Requests = new List<Google.Apis.Docs.v1.Data.Request>()
};
var request = new Google.Apis.Docs.v1.Data.Request {
ReplaceImage = new ReplaceImageRequest() {
ImageObjectId = imageObjectId,
Uri = "https://docs.google.com/uc?export=view&id=1pmXP9TFolKMQoUlXHllvIrQPlZiDxId6"
}};
batchUpdateRequest.Requests.Add(request);
DocumentsResource.BatchUpdateRequest updateRequest =
_docSercive.Documents.BatchUpdate(batchUpdateRequest, fileId);
BatchUpdateDocumentResponse updateResponse = updateRequest.Execute();
Error:
Invalid requests[0].replaceImage: Access to the provided image was forbidden. [400]
Errors [
Message[Invalid requests[0].replaceImage: Access to the provided image was forbidden.] Location[ - ] Reason[badRequest] Domain[global]
]'
and the second one is, how to industrialize this by retriving image URL from Google Drive API?
When I try getting it right now, I can only access image name and extension:
Google.Apis.Drive.v3.Data.File f = _service.Files.Get(fileId).Execute();
am I supposed to use query params for this file.get call?
Thanks for your help!
I'm trying to add products using the WooCommerce .Net Rest API. I have managed to add a product in using this. However, I can't get it to add the product image.
I have the following code for adding a product:
Product p = new Product();
p.name = "Ben";
p.description = "Testing Dan's Example Code.";
p.short_description = "I hope it works.";
p.price = 3;
await wc.Product.Add(p);
I can't find anything on how to add an image to this product though.
p.images = ??;
I have found the following JSON which is used to add images but I can't work out the c# equivalent.
"images":[
{
"src":"https://www.example.com/image.jpg",
"position":0
}
],
Does anyone have any ideas regarding this?
EDIT: I have attempted to write my own way of uploading the image and have got the following:
List<Image> productImageList = new List<Image>();
productImageList.Add(new Image()
{
name = "TEST",
src = "www.test.com",
position = 0
});
However, image does not contain a definition for these names. Is there a WooCommerce Rest version of Image that would work?
EDIT2: To answer my own question above - Yes there is.
productImageList.Add(new ProductImage()
{
name = "TEST",
src = "https://res.cloudinary.com/pricecheck/image/upload/c_pad,h_800,w_800,d_noimg.jpg/TOAQU093-1.jpg",
position = 0
});
The above code will allow me to add a product to an image. However, the image doesn't retain its Cloudinary source once it has been uploaded. The image is added to the wordpress library and the source becomes this.
productImageList.Add(new ProductImage()
{
name = "TEST",
src = "https://res.cloudinary.com/pricecheck/image/upload/c_pad,h_800,w_800,d_noimg.jpg/TOAQU093-1.jpg",
position = 0
});
Prepare the Image JSON object as per the above. I have not more idea to how to create image JSON object.
Then, You can be passed the image object as below into the product object to create the product in WooCommerce.
Product p = new Product();
p.name = "Ben";
p.description = "Testing Dan's Example Code.";
p.short_description = "I hope it works.";
p.price = 3;
p.images = productImageList;
await wc.Product.Add(p);
Please Read the official docs of WooCommerce REST API Here
I am using the Google C# API for the Custom Search and have it working and returning results, however I cannot see a way to make the paging work correctly.
Looking at what I get returned, no where does it tell me how many pages there are in the result? It just has a .Start property? Which is not much good unless I know how many 'pages' of results I have?
Am I missing something stupid here? Here is an example of the code I have so far
var svc = new CustomsearchService(new BaseClientService.Initializer { ApiKey = settings.GoogleCustomSearchApi });
var listRequest = svc.Cse.List(searchTerm);
listRequest.Cx = settings.GoogleCustomSearchEngineId;
listRequest.ImgSize = CseResource.ListRequest.ImgSizeEnum.Medium;
listRequest.Num = 10;
// List to hold everything in
var resultItems = new List<Google.Apis.Customsearch.v1.Data.Result>();
// Result set 1
listRequest.Start = 1;
var search = listRequest.Execute();
resultItems.AddRange(search.Items);
I have resulted at the moment to doing two or three calls one after the other and getting a load of results back. But I would prefer to have this properly paged.
The JSON API response has totlResults field:
https://developers.google.com/custom-search/json-api/v1/reference/cse/list#response.
It should be exposed under search.Queries
Found it, its in
search.SearchInformation.TotalResults
I'm trying to get hash image using the Facebook Ads api.
I didn't understand how to make the call.
I have the image Url as string and the image itself as Byte[].
This is the example from FB documentation:
curl -F 'test.jpg=#test.jpg' -F 'access_token=_' "https://graph.facebook.com/act_368811234/adimages"
What is the test.jpg=#test.jpg means ? It's not something that I've seen before.
You can find the relevant Facebook documentation URL at: https://developers.facebook.com/docs/reference/ads-api/adimage/
Thank you
The following part of the curl request means post a parameter named test.jpg which references a local file path within the current directory called test.jpg.
test.jpg=#test.jpg
If you're using c#, you may want to take a look at the open source library available from facebooksdk.net (note, it's not produced by Facebook):
http://facebooksdk.net/docs/making-synchronous-requests/
Using this, it will likely be a couple of lines of code:
var fb = new FacebookClient("access_token");
string attachementPath = #"C:\\image.jpg";
dynamic result = fb.Post("act_YOURACCOUNTID/adimages",
new
{
file = new FacebookMediaObject
{
ContentType = "image/jpeg",
FileName = Path.GetFileName(attachementPath)
}.SetValue(File.ReadAllBytes(attachementPath))
}
);
As you also tagged PHP, you can use the Facebook SDK which is produced by Facebook with the following code: https://github.com/facebook/facebook-php-sdk/
$facebook = new Facebook(array(
'appId' => 'YOUR_APPID',
'secret' => 'YOUR_APPSECRET',
));
$facebook->setAccessToken("YOUR_ACCESS_TOKEN");
$facebook->setFileUploadSupport(true);
$file='./test.jpg';
$args = array(
basename($file) => '#' . realpath($file),
);
$response = $facebook->api('/act_YOURACTID/adimages','post',$args);
I'm driving myself to despair trying to get an album added to a facebook page using the C# SDK..
I think my code is OK as I can successfully create an album on my own profile page through the SDK and API. So, I expect something's getting confused with my access tokens and permissions etc.
My c# code is here:
string accessToken = "TOKEN HERE";
FacebookClient facebookClient = new FacebookClient(accessToken);
var albumParameters = new Dictionary<string, object>();
albumParameters["message"] = "new message";
albumParameters["name"] = "new name";
facebookClient.Post("/412639422128107/albums", albumParameters);
The error Im getting is:
(OAuthException - #1) An unknown error has occurred.
I've read loads of posts on here and elsewhere on the web about getting the page's access token. Which I'm pretty sure I'm doing right -
I go to this page: https://developers.facebook.com/tools/explorer
I type in "me/accounts"
I see a couple of pages i'm the admin of, and grab the access token that corresponds with my page id that i'm trying to add the album to (412639422128107)
I check the permissions on this access token by going here:
https://developers.facebook.com/tools/debug/access_token?q=
I see that I've got the following permissions: create_event, create_note, manage_pages, photo_upload, publish_actions, publish_stream, read_stream, share_item, status_update, video_upload
But, I'm clearly not doing something quite right as it's not working! Please could anyone point me in the right direction?
Thanks loads in advance :)
you can create an album in the facebook page with this code.
string accessToken = "";
FacebookWebClient fbApp = new FacebookWebClient();
dynamic parametersForToken = new ExpandoObject();
parametersForToken.fields = "access_token";
try
{
dynamic me = fbApp.Get(idExternalPage, parametersForToken);
accessToken = me.access_token;
}
catch (Exception ex)
{
return;
}
FacebookClient facebookClient = new FacebookClient(accessToken);
var albumParameters = new Dictionary<string, object>();
albumParameters["message"] = "new message";
albumParameters["name"] = "new name";
facebookClient.Post("/me/albums", albumParameters);
or try this
https://developers.facebook.com/tools/explorer?method=GET&path='Page_Id'%3Ffields%3Daccess_token
Sorry i'm testing my script, and i have the same problem. (only for creating gallery)
see this bug: https://developers.facebook.com/bugs/376442565760536?browse=search_50361119879b15494037772 (the bug is fixed)