Issue happens on Win10. Eclipse 4.13.0.
I got a JFace TableViewer above a Text widget in a GridLayout. Whenever I fill the Table with content, the Text widget disappears. If I configure the shell as FillLayout it works, but that's not what I want because I've got some widgets not wanting to grab any space (like the search field, the separator, etc.).
I can't seem to find the problem, any advice?
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
public class TestDialog {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10, 10, 800, 600);
shell.setLayout(new GridLayout());
Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Link link = new Link(shell, SWT.NONE);
link.setText("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore");
link.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
Text txtSearch = new Text(shell, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
txtSearch.setMessage("Enter search phrase here");
TableViewer tableViewer = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
Table table = tableViewer.getTable();
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
Group grp = new Group(shell, SWT.NONE);
grp.setText("MyGroup:");
grp.setLayout(new FillLayout(SWT.HORIZONTAL));
grp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
Text txt = new Text(grp, SWT.WRAP);
List<String> entries = new ArrayList<String>();
for (int i = 0; i < 100; i++) {
entries.add("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore");
}
tableViewer.setInput(entries);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
The table is being expanded to show all of the lines and this is pushing everything below the table out of the window.
You need to specify a height hint for the table:
Table table = tableViewer.getTable();
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
data.heightHint = 200;
table.setLayoutData(data);
Related
welcome everybody
I moved from xamarin to Flutter
I encountered some problems
Including encryption and decryption
How can I convert this function to Dart/Flutter?
This function is required to communicate with the api
Thank you everyone
public static string encryp(string x, string encrypt)//function
{
try
{
string y = x;
byte[] etext = UTF8Encoding.UTF8.GetBytes(y);
string Code = encrypt;
MD5CryptoServiceProvider mdhash = new MD5CryptoServiceProvider();
byte[] keyarray = mdhash.ComputeHash(UTF8Encoding.UTF8.GetBytes(Code));
TripleDESCryptoServiceProvider tds = new TripleDESCryptoServiceProvider();
tds.Key = keyarray;
tds.Mode = CipherMode.ECB;
tds.Padding = PaddingMode.PKCS7;
ICryptoTransform itransform = tds.CreateEncryptor();
byte[] result = itransform.TransformFinalBlock(etext, 0, etext.Length);
string encryptresult = Convert.ToBase64String(result);
return encryptresult.ToString();
}
catch (Exception ex)
{
return (ex.Message==null ?"": ex.Message);
}
}
public static string decrypt(string x, string keyai)
{
try
{
string y = x.Replace("\0", null);
byte[] etext = Convert.FromBase64String(y);
string key = keyai;
MD5CryptoServiceProvider mdhash = new MD5CryptoServiceProvider();
byte[] keyarray = mdhash.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
TripleDESCryptoServiceProvider tds = new TripleDESCryptoServiceProvider();
tds.Key = keyarray;
tds.Mode = CipherMode.ECB;
tds.Padding = PaddingMode.PKCS7;
ICryptoTransform itransform = tds.CreateDecryptor();
byte[] result = itransform.TransformFinalBlock(etext, 0, etext.Length);
string dencryptresult = UTF8Encoding.UTF8.GetString(result);
return dencryptresult.ToString();
}
catch (Exception ex)
{
return (ex.Message==null ?"": ex.Message);
}
}
update
I wrote this code on Flutter
import 'package:dart_des/dart_des.dart' as des3;
String encryptDataE(String _plainText, String _key) {
var bytes = new List<int>.from(utf8.encode(_plainText));
var key = md5.convert(utf8.encode(_key)).bytes; //The key is any letters
des3.DES3 mDes3CBC = des3.DES3(
key: key,
mode: des3.DESMode.ECB,
paddingType: des3.DESPaddingType.PKCS7,
);
final encrypted = mDes3CBC.encrypt(bytes);
String value = base64Encode(encrypted);
return value;
}
String decryptDataD(String _plainText, String _key) {
String plainText = _plainText.replaceAll("\0", null);
var bytes = base64.decode(plainText);
var key = md5.convert(utf8.encode(_key)).bytes; //The key is any letters
des3.DES3 mDes3CBC = des3.DES3(
key: key,
mode: des3.DESMode.ECB,
paddingType: des3.DESPaddingType.PKCS7,
);
final decrypt= mDes3CBC.decrypt(bytes);
String value = utf8.decode(decrypt);
return value;
}
After experimenting with encryption and decoding, this works now
One point left, how can this be achieved?
//string y = x.Replace("\0", null);//c#
String plainText = _plainText.replaceAll("\0", null); //I tried with this and it gets an error
Consider using this tool: "Use the tool e.g. for porting your Xamarin/UWP project to Flutter"
Otherwise, there is a pretty easy Flutter Encrypt package here
//Package example
import 'package:encrypt/encrypt.dart';
void main() {
final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
final key = Key.fromUtf8('my 32 length key................');
final iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
final encrypted = encrypter.encrypt(plainText, iv: iv);
final decrypted = encrypter.decrypt(encrypted, iv: iv);
print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit
print(encrypted.base64); // R4PxiU3h8YoIRqVowBXm36ZcCeNeZ4s1OvVBTfFlZRdmohQqOpPQqD1YecJeZMAop/hZ4OxqgC1WtwvX/hP9mw==
}
I want use rsa in flutter
I have the following code for flutter
But I do not know about the part test/private.pem and test/public.pem how it is made in flutter
Of course, I have private and public keys that are made in Java with a length of 1024
Can I put them here? Or not, and must the PEM file be created? How do I generate a PEM file?
Thank you for your help
Future<void> main () async {
final publicKey = await parseKeyFromFile<RSAPublicKey>('test/public.pem');
final privKey = await parseKeyFromFile<RSAPrivateKey>('test/private.pem');
final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
final encrypter = Encrypter(RSA(publicKey: publicKey, privateKey: privKey));
final encrypted = encrypter.encrypt(plainText);
final decrypted = encrypter.decrypt(encrypted);
print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit
print(encrypted.base64); // kO9EbgbrSwiq0EYz0aBdljHSC/rci2854Qa+nugbhKjidlezNplsEqOxR+pr1RtICZGAtv0YGevJBaRaHS17eHuj7GXo1CM3PR6pjGxrorcwR5Q7/bVEePESsimMbhHWF+AkDIX4v0CwKx9lgaTBgC8/yJKiLmQkyDCj64J3JSE=
}
there are 2 ways to set publicKey and privateKey.
from your project :
create a folder named as test/
inside it
like this
inside private.pem and public.pem paste your private and public key
respectively .
and get it using
final publicKey = await parseKeyFromFile<RSAPublicKey>('test/public.pem');
final privKey = await parseKeyFromFile<RSAPrivateKey>('test/private.pem');
above approach works good when public and private keys are constant
from string :
import 'package:encrypt/encrypt.dart';
import 'package:pointycastle/asymmetric/api.dart';
String privateKeyString="key goes here";
String publicKeyString="key goes here";
//create a instance of RSA key praser
RSAKeyParser keyParser = RSAKeyParser();
//and parse those string keys
RSAAsymmetricKey privateKeyParser = keyParser.parse(privateKeyString);
RSAAsymmetricKey publicKeyParser =keyParser.parse(publicKeyString);
final publicKey = RSAPublicKey(publicKeyParser.modulus!, publicKeyParser.exponent!);
final privKey;
if (privateKeyParser is RSAPrivateKey) {
privKey = RSAPrivateKey(privateKeyParser.modulus!,privateKeyParser.exponent!, privateKeyParser.p,privateKeyParser.q);
final plainText = 'hello world';
final encrypter = Encrypter(RSA(publicKey: publicKey, privateKey:privKey));
final encrypted = encrypter.encrypt(plainText);
final decrypted = encrypter.decrypt(encrypted);
}
it worked for me!!
You can use pointy castle package to do that: https://pub.dev/packages/pointycastle
Just generate a key pair (code below) and use it in your app. Good luck!
import 'package:pointycastle/export.dart';
import 'dart:math';
import 'dart:typed_data';
AsymmetricKeyPair<RSAPublicKey, RSAPrivateKey> generateRSAkeyPair(
SecureRandom secureRandom,
{int bitLength = 2048}) {
// Create an RSA key generator and initialize it
final keyGen = RSAKeyGenerator()
..init(ParametersWithRandom(
RSAKeyGeneratorParameters(BigInt.parse('65537'), bitLength, 64),
secureRandom));
// Use the generator
final pair = keyGen.generateKeyPair();
// Cast the generated key pair into the RSA key types
final myPublic = pair.publicKey as RSAPublicKey;
final myPrivate = pair.privateKey as RSAPrivateKey;
return AsymmetricKeyPair<RSAPublicKey, RSAPrivateKey>(myPublic, myPrivate);
}
SecureRandom exampleSecureRandom() {
final secureRandom = FortunaRandom();
final seedSource = Random.secure();
final seeds = <int>[];
for (int i = 0; i < 32; i++) {
seeds.add(seedSource.nextInt(255));
}
secureRandom.seed(KeyParameter(Uint8List.fromList(seeds)));
return secureRandom;
}
// here is how you generate key pair
final pair = generateRSAkeyPair(exampleSecureRandom());
final public = pair.publicKey; // to get public
final private = pair.privateKey; // i know, you get it :D
I am trying to make a combobox in table viewer in Eclipse SWT.pointing me in the right direction.I think I've done everything ok until now, problem is the combo box not display in the table,I got error this:
Error:
Block of Code is:
public void createPartControl(Composite parent) {
System.out.println("createPartControl call");
// For Testing
Composite tableComposite = new Composite(parent, SWT.NONE);
tableColumnLayout = new TableColumnLayout();
tableComposite.setLayout(tableColumnLayout);
tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
tableViewer = new TableViewer(tableComposite, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
// TODO viewer.setLabelProvider(new ViewLabelProvider());
table = tableViewer.getTable();
// Table table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
String[] titles = { "Threat Name", "Category Name", "Status",
"Priority", "Description", "Justification" };
for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmn = tableViewerColumn.getColumn();
tableColumnLayout.setColumnData(tblclmn, new ColumnPixelData(200,
true, true));
tblclmn.setText(titles[loopIndex]);
}
}
private void fillRows(String shortdesc, String categ, String descp) {
System.out.println("fillRows call from above method.");
TableColumn status_Name_Col = tableViewer.getTable().getColumn(2);
System.out.println("**************** status_Name_Col ************ "+ status_Name_Col);
tableViewerColumn.setLabelProvider(new ColumnLabelProvider()
{
#Override
public String getText(Object element)
{
Dummy p = (Dummy) element;
return p.getValue();
}
});
tableViewer.addSelectionChangedListener(new ISelectionChangedListener()
{
#Override
public void selectionChanged(SelectionChangedEvent selectionChangedEvent)
{
StructuredSelection selection = (StructuredSelection) selectionChangedEvent.getSelection();
System.out.println(((Dummy) selection.getFirstElement()).getValue());
}
});
List<Dummy> elements = new ArrayList<>();
for (int i = 0; i < Connection.Number_Of_Connection; i++) {
elements.add(new Dummy("First option"));
}
tableViewer.setInput(elements);
tableColumnLayout.setColumnData(status_Name_Col, new ColumnWeightData(1, true));
tableViewerColumn.setEditingSupport(new FirstValueEditingSupport(tableViewer));
}
The assertion message is pretty clear - you must set a label provider for each column in the table.
You don't show us where you are calling fillRows but setting the column label provider in that method looks wrong - set the label providers in your loop creating the columns.
So now I have successfully added a TableViewer in my TitleAreaDialog.
I am trying to figure out some of layout issues I am having.
Can I control the layout and location of my tableViewer in my Dialog window.
Right now the table is showing up on the right side.
I want it to be centered in my parent Composite.
Can I add the TableViewer to a Parent Layout in the createDialogArea method?
I will be adding more composites to the Dialog and would like to be able to control where they go and how they look.
Also my table shows a half empty column at the end of the table, is there a way to remove that?
Something like:
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.CENTER;
TableViewer d = createTableViewer(area);
d.setLayoutData(gridData);
This is my createDialogArea code.
protected Control createDialogArea(Composite parent) {
final Composite area = new Composite(parent, SWT.NULL);
final GridLayout gridLayout = new GridLayout();
gridLayout.marginWidth = 15;
gridLayout.marginHeight = 10;
area.setLayout(gridLayout);
TableViewer d = createTableViewer(area);
return area;
}
Here is my tableviewer code
private TableViewer createTableViewer(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
createColumns(parent, viewer);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(AplotSelectedDataTable.getInstance().getArrayData());
// Layout the viewer
GridData gridData = new GridData(SWT.CENTER);
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
viewer.getControl().setLayoutData(gridData);
return viewer;
}
Here is a small example that should help you with your layout issues:
public class TestClass extends Dialog {
private TableViewer viewer;
protected TestClass(Shell parentShell) {
super(parentShell);
}
protected Control createDialogArea(Composite parent) {
final Composite area = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout(2, true);
gridLayout.marginWidth = 15;
gridLayout.marginHeight = 10;
area.setLayout(gridLayout);
area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
createButtons(area);
createTableViewer(area);
return area;
}
private void createButtons(Composite parent)
{
Button button1 = new Button(parent, SWT.PUSH);
button1.setText("Button1");
button1.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));
Button button2 = new Button(parent, SWT.PUSH);
button2.setText("Button2");
button2.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));
}
private void createTableViewer(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
createColumns(parent);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
// Layout the viewer
GridData gridData = new GridData(SWT.CENTER, SWT.FILL, true, true);
gridData.horizontalSpan = 2;
table.setLayoutData(gridData);
}
private void createColumns(Composite parent)
{
TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
final TableColumn column = viewerColumn.getColumn();
column.setText("Title");
column.setWidth(100);
column.setResizable(true);
column.setMoveable(false);
}
public static void main(String[] args) {
Display display = Display.getDefault();
final Shell shell = new Shell(display);
TestClass test = new TestClass(shell);
test.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
It basically creates a small Dialog with 2 buttons at the top and a centered TableViewer below. This should give you an idea on how to solve your problem.
I am using the latest SDK of Facebook C# SDK i.e. 5.0.9 Beta
I had one Text box in page in button which suppose to post the text in the users Wall.
But the problem is when I am clicking on Button the page get redirected to
something like
http://localhost:5000/facebookredirect.axd?code=JU1q_vSj13WRn1wIjHjCZRF5iDy_xvkFUppxADeS0F0.eyJpdiI6InJwejVVWXpJY1RqV0VaY1JjTl92ZGcifQ.KSa0B1ax1qCZZ-K_oXLmAZR8lyknWDRY9ieWxuLIZqXedUzb1WQH_FrcMF98VO6U1Dk5KIo4dz4AMdBxtfrUUH0ucgOoPC6_7Zb03WsIgY2fF84L-0s3A7m3f971sJUS4nQyRGDZ_-8oPuO0K0dTPg&state=eyJyIjoiaHR0cDovL2FwcHMuZmFjZWJvb2suY29tL3Rlc3RhcHBfdGVzdGluZy9Ib21lL0Fib3V0P0xlbmd0aD0zIn0
and then again redirected to my apps URL in between I am not getting any data in my controller the values are showing as null.
After analyzing HTTP call I found the content is
<html><head><script type="text/javascript">
top.location = "http://www.facebook.com/dialog/oauth/?scope=user_about_me,friends_about_me,publish_stream&state=eyJyIjoiaHR0cDovL2FwcHMuZmFjZWJvb2suY29tL3Rlc3RhcHBfdGVzdGluZy9ob21lL0Fib3V0In0&client_id=218380811509677&redirect_uri=http://localhost:5000/facebookredirect.axd";
</script></head><body></body></html>
I am using Ajax but the Behavior is same for normal as well.
It Seems like Authorizing on every Call.
Do I need to implement Oauth 2.0.
I am Using sample APP for the MVC3.
Can anyone tell me whats going wrong?
That´s a typical occurrence , when you use FacebookAuthorizeAttribute from Facebook.Web.Mvc. At least, your response-code let me assume that the oauth-handshake didn´t work properly (although you got the "code", you forgot to get your "access_token" with it)
In case you´re using FacebookAuthorizeAttribute, check if you´re app-settings in the facebook-developer-app AND your web.config have the right canvas-url/ canvas-page inserted. (In your case, for testing, "http://localhost/" / "http://apps.facebook.com/yourappname")
Recently I read a post, which said you mustn´t use the Facebook.Mvc classes, because they provide example-code.
see 1. Answer on this link
Try this code
public ActionResult Index()
{
var url = "http://www.facebook.com/v2.2/dialog/oauth/?scope=user_friends,read_friendlists,publish_actions,read_stream,read_insights,manage_pages,user_checkins,user_photos,read_mailbox,manage_notifications,read_page_mailboxes,email,user_videos,user_groups,offline_access,publish_actions,manage_pages&client_id=" + ConfigurationManager.AppSettings["ClientId"] + "&redirect_uri=" + ConfigurationManager.AppSettings["RedirectUrl"] + "&response_type=code";
return Redirect(url);
}
Call Back Url
public string AddFacebookAccount(string code)
{
string ret = string.Empty;
string client_id = ConfigurationManager.AppSettings["ClientId"];
string redirect_uri = ConfigurationManager.AppSettings["RedirectUrl"];
string client_secret = ConfigurationManager.AppSettings["ClientSecretKey"];
long friendscount = 0;
try
{
FacebookClient fb = new FacebookClient();
string profileId = string.Empty;
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("client_id", client_id);
parameters.Add("redirect_uri", redirect_uri);
parameters.Add("client_secret", client_secret);
parameters.Add("code", code);
JsonObject fbaccess_token = null;
try
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
fbaccess_token = (JsonObject)fb.Get("/oauth/access_token", parameters);
}
catch (Exception ex)
{
try
{
fbaccess_token = (JsonObject)fb.Get("/oauth/access_token", parameters);
}
catch (Exception ex1)
{
return "issue_access_token";
}
}
string accessToken = fbaccess_token["access_token"].ToString();
Session["AccessToken"] = accessToken;
if (accessToken != null)
{
fb.AccessToken = accessToken;
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
dynamic profile = fb.Get("v2.2/me");
dynamic friends = fb.Get("v2.2/me/friends");
try
{
Session["uid"] = profile.id;
friendscount = Convert.ToInt16(friends["summary"]["total_count"].ToString());
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
//return new JavaScriptSerializer().Serialize(ret);
return ret;
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
return "Something Went Wrong";
}
}
Post Text and Image Code
public ActionResult ComposeMessageSend(string message)
{
System.Net.ServicePointManager.Expect100Continue = false;
string file = Server.MapPath("~/Images/11.jpg");
message = "This is Photoshop's version of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet mauris. Morbi accumsan ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odio. Sed non mauris vitae erat consequat auctor eu in elit. Class aptent" ;
string tokenid = string.Empty;
string userid = string.Empty;
//Arvind Itact
tokenid = "CAAK1OqZAcaoMBAHxFQXf78orU2KkZCijtr5MT14VBQsB9QB4YkL6Ua3FUHcSEpss7f0dwIPofpDI0oOSH94iaOQx9tbsS7zbZAu3To6R5dKo4jQ2HGXoiiiVBIEfEoVKwieOLzT6IvZAwlqMxK8x8gqR0RG9Dgd60NwCM3XRPDHZAeoUVYpSELoQdPJS1uDbNQFBK4mgtaSVPcbkjmD1VYhpC";
userid = "1383854058392012107";
string result = FacebookComposeMessage(tokenid, userid, message, file);
return View();
}
public string FacebookComposeMessage(string tokenid,string userid ,String message,string imagepath)
{
FacebookClient fb = new FacebookClient();
string ret = "";
fb.AccessToken = tokenid;
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
var args = new Dictionary<string, object>();
args["message"] = message;
if (!string.IsNullOrEmpty(imagepath))
{
var media = new FacebookMediaObject
{
FileName = "filename",
ContentType = "image/jpeg"
};
byte[] img = System.IO.File.ReadAllBytes(imagepath);
media.SetValue(img);
args["source"] = media;
ret = fb.Post("v2.0/" + userid + "/photos", args).ToString();
}
else
{
ret = fb.Post("v2.0/" + userid + "/feed", args).ToString();
// ret = fb.Post("/" + objFacebookAccount.FbUserId + "/photos", args).ToString();
// var data = fb.Get("v2.2" + ret);
}
return ret;
}