Upload comments to particular post of facebook with object_id android - android

Hello friends I want to post comment to particular post in facebook with my android app, below is my code-
I Fetch All comments from URL which is below
http://retirementhomeslisting.com/home-detail/canterbury-place-83
Bundle mBundle=new Bundle();
mBundle.putString("message","testing...1234555");
#SuppressWarnings("deprecation")
Facebook fb=new Facebook(getResources().getString(R.string.fb_app_id));
try {
fb.request("478409145610921/comments",mBundle,"POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Here I provide one link which you can see all comment list with respective above object_id
Link for comment list for 478409145610921 object_id
When i run above code comment is not post with respective object_id so Any idea how can i solve it?
EDIT Answer
Bundle mBundle=new Bundle();
mBundle.putString("message","testing...1234555");
#SuppressWarnings("deprecation")
Facebook fb=new Facebook(getResources().getString(R.string.fb_app_id));
try {
fb.request("1309634065_478409145610921/comments",mBundle,"POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

To post a comment on a post, you need a post_id instead of object_id.
So your API call must be-
/{post_id}/comments
(post_id is also a field in the comments table)
Edit:
You must be using a comment plugin and trying to post a comment to that. Unfortunately, facebook don't allows you to do that! (Logical- since most of them are public, to avoid spamming, else anyone could flood comments to that post)
If you check the response here, you'll get:
{
"error": {
"message": "(#100) Comments may not be added to a comment plugin",
"type": "OAuthException",
"code": 100
}
}
You can test these API call on Graph API Explorer also.

Using Graph API:
...
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[[[FBSDKGraphRequest alloc]
initWithGraphPath:#"post_id/likes"
parameters: #{ #"like" : #"true"}
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"It was liked.");
}
}];
}
...

Related

FileNotFound - When trying to get asset file

I'm trying to get a file in the assetsbut when I run my code the FileNotFound exception throws. I've checked with getAssets().list(".") and really the android does not detect the file in the assets directory, but i put the file in the assets folder. I'm not a android expert and I count with the community help to help me to understand what am I doing wrong.
Follow bellow my code:
try {
Log.i("PEDRO", Arrays.toString(getResources().getAssets().list(".")));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Result: []
try {
Log.i("PEDRO", Arrays.toString(getApplicationContext().getAssets().list(".")));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Result: []
The file is in the assets directory.
try {
InputStream input =
Definitions.appContext.getAssets().open("iot.neo..........com.bks");
} catch (IOException e) {
e.printStackTrace();
}
I know that is too much important to use the Android Studio for the development of the applications, but I'm doing it on eclipse because it's a legacy code that will be changed to Android Studio before (and I'm not a responsible for that).
Thanks a lot!
Try remove ".":
try {
Log.d("PEDRO", Arrays.toString(getApplicationContext().getAssets().list("")));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

reconnecting issues in xmpp servers

i am using openfire xmpp server and asmack library to implement pubub node , the biggest issue that i face is the reconnection problem to the xmpp server.
whenever a connection is made to the xmpp server there are lots of stanza is being exchanged possibly around 5 to 7 stanza in a desktop applicaiton or web application it seems ok , but for mobile application where 3G link is pretty weak , in that case it too good to exchange so much of stanza.
i have tested that when the wifi has a weak signal or 3g link is down , i am making a reconnecting to the server (in background process) but i mostly get a response time out error and taking too much time if the connection gets successful.
i have seen messenger like whatsapp in which they are making a reconnection pretty fast. i want to do something like that only.
i have read about the pre-http binding but its exist in ejabber but didnt find anything in openfire moreover htt-prebinding is for anonymous users and i am using registered users only.
so can anyone tell me how can i reconnect fast to the xmpp server.
code snippet
Boolean onlyConnect = arg[0];
try {
if(xmpp!= null && !xmpp.isConnected())
xmpp.connect();
} catch(BOSHTimeoutException e){
Log.e("XConnection " , "Timeout occures");
// make a reconnection here
return false;
}
catch(ConnectionException e){
CatchErrors("ConnectionException" , "xmpp.connect()");
e.printStackTrace();
}catch(NoResponseException e){
CatchErrors("NoResponseException" , "xmpp.connect()");
// make a reconnection here
return false;
}catch (XMPPException e1) {
// TODO Auto-generated catch block
CatchErrors("XMPPException" , "xmpp.connect()");
e1.printStackTrace();
return false;
} catch (SmackException e) {
CatchErrors("SmackException" , "xmpp.connect()");
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
CatchErrors("IOException" , "xmpp.connect()");
e.printStackTrace();
}
try {
Log.e("LOGIN REQUIRED " , "LOGIN IN");
xmpp.login(XMPP_USER_NAME, XMPP_PASSWORD, "sh");
} catch (XMPPException e) {
// TODO Auto-generated catch block
CatchErrors("XMPPException" , "xmpp.login()");
e.printStackTrace();
return false;
} catch(NoResponseException e){
Log.e("LOGIN REQUIRED " , "NoResponseException");
CatchErrors("NoResponseException" , "xmpp.login()");
//make a reconnection here
return false;
}catch (SaslException e) {
// TODO Auto-generated catch block
CatchErrors("SaslException" , "xmpp.login()");
e.printStackTrace();
} catch (SmackException e) {
// TODO Auto-generated catch block
CatchErrors("SmackException" , "xmpp.login()");
e.printStackTrace();
} catch (IOException e) {
CatchErrors("IOException" , "xmpp.login()");
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}

Not able to Post facebook Checkin status Android

Error:
Response={ "error": { "message": "(#100) Requires extended permission: publish_checkins or publish_actions", "type": "OAuthException", "code": 100 }}
Source Code:
Bundle params1 = new Bundle();
params1.putString("access_token",token);
params1.putString("place", "566414493392930"); // YOUR PLACE ID
params1.putString("message","I m here in this place");
JSONObject coordinates = new JSONObject();
try {
coordinates.put("latitude", "30.902823300000000000");
coordinates.put("longitude", "75.830516900000020000");
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
params1.putString("coordinates",coordinates.toString());
params1.putString("tags",params[0]);//where xx indicates the User Id
String response="";
try {
response =faceBook.request("me/checkins", params1, "POST");
Log.v("Response","Response="+response);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Well, the error says that the permissions: publish_checkins or publish_actions is required. To remove this error, simply add these permissions while authenticating the user. See how it is done: Android login- permissions
But, the thing is- the API checkins have been deprecated. Check here it says-
Checkins have been deprecated in favor of attaching place information to posts, or tagging places in Open Graph stories. Please check the related guides for information.
So your code shall not work anyway. You'll now have to use Open Graph Actions for the same. There's step wise tutorial for the same in the documentation, just go through it and implement. Good luck.

How can i get product information from barcode in android? [duplicate]

This question already has answers here:
Getting Product information like name, price etc using barcode number
(4 answers)
Closed 8 years ago.
Google has shut down the Search API for Shopping so what is the possible way to get product info ( manufacturer name, product number etc.) from barcode in android?
Try this api from www.outpan.com
try {
json = products(upc);
return json.getString(params[0]);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Once visit this this may helpful to you

Sip Profile Building:Android

I could build a sip profile using SipProfile.Builder class. I used following snippet of code to do it:
if (SipManager.isApiSupported(MyActivity.this)&& SipManager.isVoipSupported(MyActivity.this)) {
SipManager manager=SipManager.newInstance(this);
SipProfile.Builder builder;try {
builder = new Builder(userName,domainName);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} manager = SipManager.newInstance(MyActivity.this);
builder.setPassword(password);
profile = builder.build();
try {
manager.open(profile);
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
manager.register(profile, 30, MyActivity.this);
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(MyActivity.this, "created",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MyActivity.this, "Not Supported",
Toast.LENGTH_LONG).show();
}
It shows as a sip account in the settings/callsettings/Internet call settings.
Problem is i could not make it as primary account. How can i make it as primary account?
This information is account-based (primary email address for person, primary phone number, primary SIP account etc.) so it's stored in the phone's contacts-book.
It seems to me it's an option that is set per-data, per-account (for example: this type of data (email/phone/sip-addr) set it as primary).
You can set data as primary for a contact using IS_PRIMARY or IS_SUPER_PRIMARY
IS_PRIMARY: Whether this is the primary entry of its kind for the raw
contact it belongs to.
The data you should use it on is ContactsContract.CommonDataKinds.SipAddress. I hope that's useful as starting point.

Categories

Resources