I am trying to update my page app image with graph api but nothing happens. i have right access token , i could change the custom_name but not custom_image.
var fbdc = new Dictionary<string, object>();
fbdc.Add("access_token", AccessToken);
fbdc.Add("custom_name", Name);
fbdc.Add("custom_image",Image);
result = fb.Post(tab.id, fbdc);
I get the result true from graph api but still the image doesnt change.My image is 111*74.jpg. i was able to upload the same image manually but not through graph api.
Am i doing some thing wrong ?
var fbparams = new Dictionary<string, object>();
string path = #"c:\test.jpg";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
var picture = new FacebookMediaObject
{
//Tell facebook that we are sending image
ContentType = "image/jpeg",
//Give name to the image
FileName = "test"
};
//Create a new byteArray with right length
var img = tabImageInfo.Media;
//Convert the image content into bytearray
fs.Read(img, 0, img.Length);
//Close the stream
fs.Close();
//Put the bytearray into Picture
picture.SetValue(img);
//Add the image into parameters
fbparams.Add("custom_image", picture);
fb.Post(tab.id, fbparams);
Related
I'm using iTextSharp to update an image object in a PDF with a modified System.Drawing.Image. How do I properly set the PdfName.COLORSPACE and PdfName.FILTER based on the System.Drawing.Image? I'm not sure which System.Drawing.Image properties can be used for the mappings.
private void SetImageData(PdfImageObject pdfImage, System.Drawing.Image image, byte[] imageData)
{
PRStream imgStream = (PRStream)pdfImage.GetDictionary();
imgStream.Clear();
imgStream.SetData(imageData, false, PRStream.NO_COMPRESSION);
imgStream.Put(PdfName.TYPE, PdfName.XOBJECT);
imgStream.Put(PdfName.SUBTYPE, PdfName.IMAGE);
imgStream.Put(PdfName.WIDTH, new PdfNumber(image.Width));
imgStream.Put(PdfName.HEIGHT, new PdfNumber(image.Height));
imgStream.Put(PdfName.LENGTH, new PdfNumber(imageData.LongLength));
// Not sure how to properly set these entries based on the image properties
imgStream.Put(PdfName.BITSPERCOMPONENT, 8);
imgStream.Put(PdfName.COLORSPACE, PdfName.DEVICERGB);
imgStream.Put(PdfName.FILTER, PdfName.DCTDECODE);
}
I took the advice of Chris Haas and cheated by writing the System.Drawing.Image to a temporary PDF and then read it back out as a PdfImageObject.
using (MemoryStream ms = new MemoryStream())
{
using (iTextSharp.text.Document doc = new iTextSharp.text.Document())
{
using (iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc))
{
doc.Open();
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(drawingImage, drawingImage.RawFormat);
image.SimplifyColorspace();
doc.Add(image);
doc.Close();
}
}
... code that opens the mem stream with PdfReader and retrieves the image as PdfImageObj...
}
That worked but seemed like allot of side stepping for a cheat. I stepped through the code in the call to doc.Add(image) and found that eventually a PdfImage object was created from the iTextSharp.text.Image object and the PdfImage object contained all the dictionary entries that I needed. So I decided to cut some corners on the original cheat and come up with this as my final solution:
private void SetImageData(PdfImageObject pdfImageObj, byte[] imageData)
{
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imageData);
image.SimplifyColorSpace();
PdfImage tempPdfImage = new PdfImage(image, "TempImg", null);
PRStream imgStream = (PRStream)pdfImageObj.GetDictionary();
imgStream.Clear();
imgStream.SetDataRaw(imageData);
imgStream.Merge(tempPdfImage);
}
I am trying to get my app (iOS, Android) to allow users to post a screenshot to facebook with a link and a description. I am able to use FB.API() to upload screenshots from my app to a user's album that Facebook autogenerated for my app, via:
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] screenshot = tex.EncodeToPNG();
var wwwForm = new WWWForm();
string picName = "Idioman_" + Time.time + ".png";
wwwForm.AddBinaryData("image", screenshot, picName);
Debug.Log("trying to post screenshot");
FB.API("me/photos", Facebook.HttpMethod.POST, PostPicCallback, wwwForm);
And I am able to use FB.Feed() to post an image from the internet with a link and a description to a user's feed. Is there a way to post the screenshot to a user's feed with a link and a description?
var snap = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
snap.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
snap.Apply();
var screenshot = snap.EncodeToPNG();
int i = UnityEngine.Random.Range (0, 2);
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", screenshot, "picture.png");
wwwForm.AddField ("name", "this will be the caption for the image");
FB.API("me/photos", HttpMethod.POST, CallbackUploadImage, wwwForm);
you can refer here for more details of the available fields
https://developers.facebook.com/docs/graph-api/reference/v2.2/photo
After you upload the screenshot using your code above, check the FBResult from your callback method and parse the result with key "id" so you got your uploaded photo id.
Your photo link will be "https://www.facebook.com/photo.php?fbid=INSERT_YOUR_ID" as the INSERT_YOUR_ID is the id from the result before. Use that link on FB.Feed.
Follow these steps:
First login using FB.LogInWithPublishPermissions by adding the "publish_actions" permission in parameters.
Use Facebook Graph API to upload the image.
For more details link is here.
I'm trying to change a facebook page tab image programatically. The idea is when my app will finish the instalation process, it will be change the image of the tab where it place it. After finish the process and give permissions to the app, The response of fb is "unautorized"
{"error":{"message":"(#300) Edit failure","type":"OAuthException","code":300}}
I searched about this error, the most close aproach was: https://developers.facebook.com/bugs/255313014574414/.
I tried the same CURL example described in the error and have the same response.
The strange thing is, when i tried change the image inside fb, it fails too. I think the problem is when the app ask permissions to install in the user page, and don't have enough permits.
But i don't know hot i chage the permit to authorize chage the image of the pagetab.
var fbparams = new Dictionary<string, object>();
string path = #"c:\test.jpg";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
var picture = new FacebookMediaObject
{
//Tell facebook that we are sending image
ContentType = "image/jpeg",
//Give name to the image
FileName = "test"
};
//Create a new byteArray with right length
var img = tabImageInfo.Media;
//Convert the image content into bytearray
fs.Read(img, 0, img.Length);`enter code here`
//Close the stream
fs.Close();
//Put the bytearray into Picture
picture.SetValue(img);
//Add the image into parameters
fbparams.Add("custom_image", picture);
fb.Post(tab.id, fbparams);
I'm trying to make a photo organizing Facebook application without using server-side process.
Now I can preview photos by using FileReader object's readAsDataURL method, such as...
var file = e.dataTransfer.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var imgObj = $(document.createElement('img')).attr('src',reader.result).appendTo('#image_preview_wrapper');
};
reader.readAsDataURL(file);
}, false);
The question is how to post the image data to Facebook.
I'm trying to do something like
var reader = new FileReader();
reader.onload = function(e) {
var data = reader.result;
FB.api('/me/photos','post',{ image : data },function(res){
alert(res);
});
}
reader.readAsBinaryString(file);
In this case, I can't set enctype="multipart/form-data" and I'm getting 400 Bad Request.
Can anybody help me?
I'm having a problem trying to locate a PdfContentByte directly into an specific page. My problem is: I need to add an Image for each page (That works) and need to add a QRCode to each of the pages at the right bottom corner but this works only for the first Page and I don't know how to repeat it on the other ones.
This is my code:
public string GeneratePDFDocument(Atomic.Development.Montenegro.Data.Entities.Document document, Stamp stamp)
{
string filename = #"C:\Users\Sheldon\Desktop\Pdf.Pdf";
FileStream fs = new FileStream(filename, FileMode.Create);
iTextSharp.text.Document pdfDocument = new iTextSharp.text.Document(PageSize.LETTER, PAGE_LEFT_MARGIN, PAGE_RIGHT_MARGIN, PAGE_TOP_MARGIN, PAGE_BOTTOM_MARGIN);
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDocument, fs);
pdfDocument.Open();
int count = document.Pages.Count;
foreach (Page page in document.Pages)
{
Image img = Image.GetInstance(page.Image);
img.ScaleToFit(PageSize.LETTER.Width-(PAGE_LEFT_MARGIN + PAGE_RIGHT_MARGIN), PageSize.LETTER.Height-(PAGE_TOP_MARGIN + PAGE_BOTTOM_MARGIN));
pdfDocument.Add(img);
PlaceCodeBar(writer);
}
pdfDocument.Close();
writer.Close();
fs.Close();
return filename;
}
private static void PlaceCodeBar(iTextSharp.text.pdf.PdfWriter writer)
{
String codeText = "TEXT TO ENCODE";
iTextSharp.text.pdf.BarcodePDF417 pdf417 = new iTextSharp.text.pdf.BarcodePDF417();
pdf417.SetText(codeText);
Image img = pdf417.GetImage();
iTextSharp.text.pdf.BarcodeQRCode qrcode = new iTextSharp.text.pdf.BarcodeQRCode(codeText, 1, 1, null);
img = qrcode.GetImage();
iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
cb.SaveState();
cb.BeginText();
img.SetAbsolutePosition(PageSize.LETTER.Width-PAGE_RIGHT_MARGIN-img.ScaledWidth, PAGE_BOTTOM_MARGIN);
cb.AddImage(img);
cb.EndText();
cb.RestoreState();
}
So add it in your foreach (Page...) loop:
foreach (Page page in document.Pages)
{
Image img = Image.GetInstance(page.Image);
img.ScaleToFit(PageSize.LETTER.Width-(PAGE_LEFT_MARGIN + PAGE_RIGHT_MARGIN), PageSize.LETTER.Height-(PAGE_TOP_MARGIN + PAGE_BOTTOM_MARGIN));
pdfDocument.Add(img);
PlaceCodeBar(writer);
}
If this is a second pass on the same PDF (you've closed it then opened it again), use a PdfStamper rather than a PdfWriter. You can then get the direct content of each page rather than the one direct content that is reused (and reset) for each page.
PS: Drop the BeginText() and EndText() calls. Those operators should only be used when actually drawing text/setting fonts/etc. No line art. No images. The SaveState()/RestoreState() are good though. Definitely keep those.
I just figure out how to solve the problem. Just delete the cb.SaveState() and cb.RestoreState() and it put the image on the page is actually active.