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);
Related
Attempting this on .NET Core 3.1
After several hours of trying to publish a photo to my public facebook page (as in business page) of which I am the admin and have a long-term token for...
I keep getting the following response to my request using the official Facebook SDK for .NET. However, the image itself is never loaded.
{{"id":"786692942226147","post_id":"113260773923227_786692942226147"}}
The request looks like
var imageMedia = new FacebookMediaObject { FileName = file.FileName, ContentType = file.ContentType };
var stream = file.OpenReadStream();
var bytes = await stream.ReadAsByteArrayAsync();
imageMedia.SetValue(bytes);
var fbClient = new FacebookClient(credential.Token)
{
AppId = _config.GetValue<string>("FacebookClientId"),
AppSecret = _config.GetValue<string>("FacebookSecret")
};
dynamic parameters = new ExpandoObject();
parameters.message = request.Message;
parameters.file = imageMedia;
var result = await fbClient.PostTaskAsync($"{credential.PageId}/photos", parameters, token);
I'm sure it has something to do with the parameters I'm passing in, like parameters.file... but the docs for this thing are VERY unclear... as in "literally does not exist"
Anyone with experience getting this working, please point me in the right direction?
The solution is to change parameters.file to parameters.image...
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 using amazon sdk for .net
i have uploaded a file in folder of my bucket , now i want to get the url of that file using this code
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest();
request.BucketName = "my-new-bucket2";
request.Key = "Images/Tulips.jpg";
request.Expires = DateTime.Now.AddHours(1);
request.Protocol = Protocol.HTTP;
string url = s3.GetPreSignedURL(request);
but this is returning url with key , exipration date and signature but infact i want to get the url without them , there is no other method to get the url
**Things i tried **
i search and found that i have to change permission of my file
i have change the permission of file while uploading
request.CannedACL = S3CannedACL.PublicRead;
but still its returning the same url
http://my-new-bucket2.s3-us-west-2.amazonaws.com/Images/Tulips.jpg?AWSAccessKeyId=xxxxxxxxxxxx&Expires=1432715743&Signature=xxxxxxxxxxx%3D
it work when i remove keyid ,expire and signature
but how can i get url with out it , or do i have to do it manually
This is by design. If you know the bucket name and the key then you have everything you need to construct the URL. As an example, here bucketname is yourbucketname and the key is this/is/your/key.jpg.
https://yourbucketname.s3.amazonaws.com/this/is/your/key.jpg
Hope that helps!
I just browsed their documentation and was not able to find a method to return an absolute url. However, I really believe there is one that I could not see. For now, you can solve your problem by extracting an absolute url from the result you have:
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest();
request.BucketName = "my-new-bucket2";
request.Key = "Images/Tulips.jpg";
request.Expires = DateTime.Now.AddHours(1);
request.Protocol = Protocol.HTTP;
string url = s3.GetPreSignedURL(request);
index = url.IndexOf("?");
if (index > 0)
string absUrl = url.Substring(0, index);
Hope it helps :)
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.
I am querying a Picasa gallery and when I dig into the entries that are returned, I can't find the full size image. I can only see a much smaller, re-sized image (data[0].Content.AbsoluteUri). I know Google retains the full size image because I can see it when I view my Picasa gallery online. Where is the full size image?
var picasaService = new PicasaService("Gallery");
var photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri("GOOGLEUSERNAME", "GALLERYID"));
var photoFeed = picasaService.Query(photoQuery);
var data = photoFeed.Entries;
Hidden in the documentation it is possible to specify the size of the images in the feed. This is using the "imgmax" parameter:
https://developers.google.com/picasa-web/docs/2.0/reference#Parameters
Which can have a value set to "d" to request full sized images
This is not supported directly in the c# API, but you can achieve the desired result using the "extraParameters" field on the PhotoQuery object.
Your code then becomes:
var picasaService = new PicasaService("Gallery");
var photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri("GOOGLEUSERNAME", "GALLERYID"));
// add the extra parameter to request full size images
photoQuery.ExtraParameters = "imgmax=d";
var photoFeed = picasaService.Query(photoQuery);
var data = photoFeed.Entries;
short answer:
media:group/media:content[#url] path in a query to get the gdata photo ENTRY from the picasa GData service contains the link you want.
Longer answer:
interactively query the Gdata api for picasa using oauth playground\
https://code.google.com/oauthplayground and select picasa from the list and get
authorize button ... then allow access button and you can query the api using the form
make a query for the ENTRY URI of desired photo (your ...user/.. /albumid .. /photoid )
inspect the content of media:group/media:content[#url] sample below
The URI to the big photo is valueOf the url attribute in the above expression
sample value for one of my picasa photos
url=https://lh3.googleusercontent.com/-_FFMNGPU1TQ/TtukXyN4eCI/AAAAAAAACso/EzPmut2iKVQ/DSC01612.JPG
Using the oauth 2.0 playground for a query to get the entry of one of my photos...
Request:
GET /data/entry/api/user/rowntreerob/albumid/5682316071017984417/photoid/5682316083381958690?alt=json
Note: filter response using http://json.parser.online.fr/
Response:
"media$group":{
"media$content":[
{
"url":"https://lh3.googleusercontent.com/-_FFMNGPU1TQ/TtukXyN4eCI/AAAAAAAACso/EzPmut2iKVQ/DSC01612.JPG",
"height":512,
"width":341,
"type":"image/jpeg",
"medium":"image"
}
The link to the large photo that you want is in the url attribute above...
Using the "fields=" tag, you can directly get the link as in below req/ resp from gdata...
GET /data/entry/api/user/rowntreerob/albumid/5682316071017984417/photoid/5682316083381958690?alt=json&fields=media%3Agroup%2Fmedia%3Acontent%5B%40url%5D
{
"version":"1.0",
"encoding":"UTF-8",
"entry":{
"xmlns":"http://www.w3.org/2005/Atom",
"xmlns$media":"http://search.yahoo.com/mrss/",
"media$group":{
"media$content":[
{
"url":"https://lh3.googleusercontent.com/-_FFMNGPU1TQ/TtukXyN4eCI/AAAAAAAACso/EzPmut2iKVQ/DSC01612.JPG",
"height":512,
"width":341,
"type":"image/jpeg",
"medium":"image"
}
]
}
}
}