am developing an app with sharing text and multiple images in a single post using facebook sdk. I used the following code, but nothing happens in my fb wall post. Whats wrong in the code please anybody help. thanks in advance.
private void publishImage() {
ArrayList<SharePhoto> sharePhotos = new ArrayList<>();
int imageFolderSize;
File imageFolder = new File(getActivity().getExternalCacheDir(), "attachments/images");
if( imageFolder.exists()) {
imageFolderSize = imageFolder.listFiles().length;
ArrayList<File> attachments = new ArrayList<>();
if (imageFolder.exists()) {
Collections.addAll(attachments, imageFolder.listFiles());
}
if (imageFolderSize > 0) {
for (int i = 0; i < attachments.size(); i++) {
File file = attachments.get(i);
if (file.exists()) {
if (file.getAbsolutePath().endsWith(".png")) {
try {
SharePhoto photo = new SharePhoto.Builder().setBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()))
.setCaption("Welcome To Facebook Photo Sharing on steroids!")
.build();
sharePhotos.add(photo);
}catch (Exception e){
RMLog.debug("Execp: e"+e.toString());
}
}
}
}
}
}
SharePhotoContent scontent = new SharePhotoContent.Builder().addPhotos(sharePhotos
).build();
if(ShareDialog.canShow(SharePhotoContent.class))
{ ShareApi.share(scontent, null);
Toast.makeText(getActivity(), "Succsesfully posted on your wall",
Toast.LENGTH_LONG).show();
}
}
Related
I needed to get to a different page if certain conditions were meet within my SurfaceController. If you have the page ID of the page you need to get to this is ease. The problem was I did not want to hard code a page id in the action method in the controller. I had a lot of problems trying to figure it out, so I thought I would provide my solution in case someone else is having the same issue.
int homePageID = 0;
try
{
homePageID = Umbraco.ContentAtXPath("//home").FirstOrDefault().Id;
}
catch(Exception e) { }
if(homePageID > 0)
{
return RedirectToUmbracoPage(homePageID);
}
else
{
return CurrentUmbracoPage();
}
Note that for this line "homePageID = Umbraco.ContentAtXPath("//home").FirstOrDefault().Id;" you use the page alias not the page name.
I hope this helps.
int homePageID = 0;
try
{
homePageID = Umbraco.ContentAtXPath("//home").FirstOrDefault().Id;
}
catch(Exception e) { }
if(homePageID > 0)
{
return RedirectToUmbracoPage(homePageID);
}
else
{
return CurrentUmbracoPage();
}
i'm developpig an app in which i need to call the fb graphrequest multiple times , but those calls needs to be one after the other, the first one will get me the user friends, and the other calls will be done in a loop (for each friend ) get the "likes" that that friend made, now with the code that i made, the first one gives me the friends but the second one (the loop instruction) won't work, i guess it has somehing to do with the async calls but i don't know how to make them serial calls, here's my code :
GraphRequest request = GraphRequest.newMyFriendsRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONArrayCallback() {
#Override
public void onCompleted(JSONArray array, GraphResponse response) {
JSONObject jsonArray = response.getJSONObject();
try {
length = jsonArray.getJSONArray("data").length();
for (int i = 0; i < length; i++) {
AlertDialog a = new AlertDialog.Builder(liste_peronalisee.this).create();
a.setTitle("Erreur");
id[i] = jsonArray.getJSONArray("data").getJSONObject(i).getString("id");
a.setMessage(id[i]);
a.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
request.executeAsync();
for(int i=0;i<id.length;i++)
request = GraphRequest.newGraphPathRequest(
AccessToken.getCurrentAccessToken(),
"/".concat(id[i]).concat("/likes"),
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
JSONObject jsonArray = response.getJSONObject();
try {
length = jsonArray.getJSONArray("data").length();
for (int i = 0; i < length; i++) {
AlertDialog a = new AlertDialog.Builder(liste_peronalisee.this).create();
a.setTitle("Erreur");
id[i] = jsonArray.getJSONArray("data").getJSONObject(i).getString("name");
a.setMessage(id[i]);
a.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
request.executeAsync();
i need a quick answer, thanks in advance
I need to post both text and images on a Facebook wall. For that, I can't use intent sharing because I want to share text too. So I implemented the Facebook SDK. But I still can't see my text content / caption on the wall. Here is my code.
private void publishImage() {
ArrayList<SharePhoto> sharePhotos = new ArrayList<>();
int imageFolderSize;
File imageFolder = new File(getActivity().getExternalCacheDir(), "attachments/images");
if( imageFolder.exists()) {
imageFolderSize = imageFolder.listFiles().length;
ArrayList<File> attachments = new ArrayList<>();
if (imageFolder.exists()) {
Collections.addAll(attachments, imageFolder.listFiles());
}
if (imageFolderSize > 0) {
for (int i = 0; i < attachments.size(); i++) {
File file = attachments.get(i);
if (file.exists()) {
if (file.getAbsolutePath().endsWith(".png")) {
try {
SharePhoto photo = new SharePhoto.Builder().setBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()))
.setCaption("Welcome To Facebook Photo Sharing on steroids!")
.build();
sharePhotos.add(photo);
}catch (Exception e){
RMLog.debug("Execp: e"+e.toString());
}
}
}
}
}
}
SharePhotoContent scontent = new SharePhotoContent.Builder().addPhotos(sharePhotos ).build();
if(ShareDialog.canShow(SharePhotoContent.class))
{
shareDialog.show(scontent);
Toast.makeText(getActivity(), "Succsesfully posted on your wall",
Toast.LENGTH_LONG).show();
}
}
i want epubreder source code in mono touch c# for iPad i got it in Xcode but need to convert in c#...
problem of conversion is that i want to parse the container.xml to get the .opf file path and again parse the .opf file....
can any one please help me out to solve this problem...
public void parseXMLFileAt(string strUrl)
{
try
{
NSMutableDictionary dict=new NSMutableDictionary();
XmlTextReader reader = new XmlTextReader("/Users/krunal/Desktop/container.xml");
string strAttribute="";
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
Hashtable attributes = new Hashtable();
string strURI= reader.NamespaceURI;
string strName= reader.Name;
if (reader.HasAttributes)
{
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
attributes.Add(reader.Name,reader.Value);
}
}
parser(_parser,strUrl,strURI,strName,dict);
enter code here
StartElement(strURI,strName,strName,attributes);
break;
default:
break;
}
}
}
catch (XmlException e)
{
Console.WriteLine("error occured: " + e.Message);
}
}
Thanks in advance
Any examples, tips, guidance for the following scenario?
I have used Apache HttpClient to simulate the functionality of browser to access facebook through java application. to do that first i have to provide user credentials. i have used examples provided in the following web site.
http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/
But non of these methods works for facebook, following is the test code i have written for this purpose. i have not provided the all the methods written, only the method used to login to the facebook account is given here. relay appreciate any help
private static int connectAndLogin(String email, String pass){
logger.trace("Facebook: =========connectAndLogin begin===========");
String httpResponseBody = getMethod("http://www.facebook.com/login.php");
if(httpResponseBody == null){
//Why don't we try again?
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
logger.trace(e.getMessage());
}
httpResponseBody = getMethod("http://www.facebook.com/login.php");
}
logger.trace("Facebook: ========= get login page ResponseBody begin===========");
logger.trace(httpResponseBody);
logger.trace("Facebook: +++++++++ get login page ResponseBody end+++++++++");
logger.trace("Facebook: Initial cookies: ");
List<Cookie> cookies = getCookies();
if (cookies.isEmpty()) {
logger.trace("Facebook: None");
} else {
for (int i = 0; i < cookies.size(); i++) {
logger.trace("Facebook: - " + cookies.get(i).toString());
}
}
if(httpResponseBody == null){
logger.warn("Facebook: Warning: Failed to get facebook login page.");
}
try
{
HttpPost httpost = new HttpPost("http://www.facebook.com/login.php");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("email", email));
nvps.add(new BasicNameValuePair("pass", pass));
//don't know if is this necessary
nvps.add(new BasicNameValuePair("login", ""));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
logger.info("Facebook: #executing post method to:" + "http://www.facebook.com/login.php");
HttpResponse loginPostResponse = getHttpClient().execute(httpost);
HttpEntity entity = loginPostResponse.getEntity();
logger.trace("Facebook: Login form post: " + loginPostResponse.getStatusLine());
if (entity != null) {
logger.trace("Facebook: "+EntityUtils.toString(entity));
entity.consumeContent();
} else {
logger.error("Facebook: Error: login post's response entity is null");
return FacebookErrorCode.kError_Login_GenericError;
}
logger.trace("Facebook: Post logon cookies:");
cookies = getCookies();
if (cookies.isEmpty()) {
logger.trace("Facebook: None");
} else {
for (int i = 0; i < cookies.size(); i++) {
logger.trace("Facebook: - " + cookies.get(i).toString());
}
}
int statusCode = loginPostResponse.getStatusLine().getStatusCode();
logger.info("Facebook: Post Method done(" + statusCode + ")");
switch(statusCode){
case 100: break;//we should try again;
case 301:
case 302:
case 303:
case 307:
{
//redirect
// Header[] headers = loginPostResponse.getAllHeaders();
// for (int i=0; i<headers.length; i++) {
// logger.trace("Facebook: "+headers[i]);
// }
// Header locationHeader = loginPostResponse.getFirstHeader("location");
// if(locationHeader != null){
// homePageUrl = locationHeader.getValue();
// logger.info("Facebook: Redirect Location: " + homePageUrl);
// if(homePageUrl == null
// || !homePageUrl.contains("facebook.com/home.php")){
// logger.error("Facebook: Login error! Redirect Location Url not contains \"facebook.com/home.php\"");
// return FacebookErrorCode.kError_Login_GenericError;
// }
// } else {
// logger.warn("Facebook: Warning: Got no redirect location.");
// }
}
break;
default:;
}
}
catch (IOException ioe)
{
logger.error("Facebook: IOException\n" + ioe.getMessage());
return FacebookErrorCode.kError_Global_ValidationError;
}
logger.trace("Facebook: =========connectAndLogin end==========");
return FacebookErrorCode.Error_Global_NoError;
}
The following code, based on that sample, worked for me:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://www.facebook.com/login.php");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
System.out.println("Initial set of cookies:");
List<Cookie> cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}
HttpPost httpost = new HttpPost("http://www.facebook.com/login.php");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("email", "******"));
nvps.add(new BasicNameValuePair("pass", "*******"));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
entity = response.getEntity();
System.out.println("Double check we've got right page " + EntityUtils.toString(entity));
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
System.out.println("Post logon cookies:");
cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}
httpclient.getConnectionManager().shutdown();
I am not sure if your code was managing properly cookies (and session id kept within one of them), maybe that was the problem. Hope this will help you.
Just to make clear version issue: I was using HttpClient version 4.X, not the old one (3.X). They differ significantly.
Perhaps you should use a tool, such as Selenium
Have you taken a look at HtmlUnit. It wraps the HttpClient to create a headless Java browser, with javaScript execution. This way you are not trying to hack the individual forms all the time.