I am trying to send invitation from my app to facebook friends. everything is working fine, facebook invitation dialog is being shown, my frinds list is there, I am also receiving status in onComplete but on the other side (to whom I send invitation) nothing happens. not notification is being sent to my frinds. please let me know where I am wrong. below is my code.
private void inviteFriends() {
try {
Bundle params = new Bundle();
params.putString("title", "invite friends");
params.putString("message", "come join us!");
mFacebook.dialog(this, "apprequests", params, new DialogListener() {
#Override
public void onComplete(Bundle values) {
try {
// JSONObject eventResponse = new JSONObject(response);
// event_id = event.getString("id");
/*
* Log.i(TAG, "Event Response => "+eventResponse);
* Log.w("myapp", friends);
*/
System.out.println("fb invite response "
+ values.toString());
Toast.makeText(getApplicationContext(), "Request sent",
Toast.LENGTH_SHORT).show();
// Toast.makeText(getApplicationContext(),
// "New Event Created!!", Toast.LENGTH_LONG).show();
} catch (Exception e) {
}
}
#Override
public void onFacebookError(FacebookError error) {
}
#Override
public void onCancel() {
}
#Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
});
} catch (Exception e) {
}
}
now problem is that request is sent but notification comes in facebook app not in facebook browser?
You should use the Message Dialog to invite friends in an Android App, the App Requests are only for Canvas Games: https://developers.facebook.com/docs/apps/faq#invite_to_app
(See "If your app does not have a presence on Facebook Canvas")
More information: https://developers.facebook.com/docs/android/share#message-dialog
Related
I'm trying to post on facebook from my android app. It is working fine using previously created app id.
Some thread is saying it is because of publish_actions.
But using new on it is giving following error.
Response: {"error":{"message":"(#200) Requires extended permission: publish_actions","type":"OAuthException","code":200}}
My posting code is below:
public void shareVideoInFacebook() {
mPrefs = getPreferences(MODE_PRIVATE);
byte[] data = null;
// shareAdvertisement();
String link = "http://techslides.com/demos/sample-videos/small.mp4";
String dataMsg = "Share for DateClip";
Bundle param;
facebook = new Facebook(APP_ID);
System.out.println("Access Token: " + pref.getFbAccessToken());
facebook.setAccessToken(pref.getFbAccessToken());
facebook.setAccessExpires(pref.getFbAccessExpire());
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
InputStream is = null;
try {
// is = new FileInputStream(dataPath);
// data = readBytes(is);
param = new Bundle();
param.putString("message", dataMsg);
param.putString("filename", "DateClip");
// param.putByteArray("video", data);
param.putString("name", "DateClip");
param.putString("caption",
"Build great social apps and get more installs.");
param.putString("description", "Watch the Video");
param.putString("link", link);
// param.putString("picture",
// "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
mAsyncRunner.request("me/feed", param, "POST",
new RequestListener() {
#Override
public void onMalformedURLException(
MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
#Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
System.out.println("IO Exception.........");
}
#Override
public void onFileNotFoundException(
FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
// Toast.makeText(getApplicationContext(),
// "File not found...", Toast.LENGTH_LONG).show();
System.out.println("FileNotfound.........");
}
#Override
public void onFacebookError(FacebookError e,
Object state) {
// TODO Auto-generated method stub
// Toast.makeText(getApplicationContext(),
// "Error...", Toast.LENGTH_LONG).show();
System.out.println("Error.........");
}
#Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
// Toast.makeText(getApplicationContext(),
// "Sharing Completed...",
// Toast.LENGTH_LONG).show();
System.out
.println("Successfully Sent.......................................................");
System.out.println("Response: " + response);
runOnUiThread(new Runnable() {
public void run() {
// UI code goes here
Toast.makeText(getApplicationContext(),
"Successfully shared on Facebook.",
Toast.LENGTH_LONG).show();
// shareForPassionPoint();
}
});
}
}, null);
// mAsyncRunner.request(dataPath, parameters, httpMethod, new F,
// state);
} catch (Exception e) {
e.printStackTrace();
}
}
Please help me.
This was the case with out iOS app. It may be the same for Android also.
"
Please get your app reviewed again.
Recently, all the permissions except 3 basic ones (email, public_profile and user_friends) have been removed from the app if you had it reviewed by an older version of the Graph API.
Follow the steps as described here: https://developers.facebook.com/docs/facebook-login/review
"
Hope this helps :)
I am working in an application which requires to send tweets on Twitter Account. I am successfully able to login and fetching details of user. But however when i try to update status Code of Twitter. It's throwing a runtime exception as per below:-
java.lang.IllegalStateException: Authentication credentials are missing. See http://twitter4j.org/configuration.html for the detail.
Even url is not available which is being shown in Exception. This is truly confusing.
i am using following code. Please help.
AccessToken accessToken = getAccessToken();
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(CONSUMER_KEY)
.setOAuthConsumerSecret(CONSUMER_SECRET)
.setOAuthAccessToken(accessToken.getToken())
.setOAuthAccessTokenSecret(accessToken.getTokenSecret());
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getSingleton();
// twitter.setOAuthAccessToken(accessToken);
String latestStatus = "Hello Dude";
try {
twitter4j.Status status = twitter.updateStatus(latestStatus);
Toast.makeText(HomeActivity.this, "Successfully tweet==="+status.getText(), Toast.LENGTH_LONG).show();
} catch (Exception e) {
// TODO: handle exception
System.out.println("Exception in Ststus update in android=="+e.getMessage());
}
I am using same library for sending tweet on Twitter. You might have code wrong to work it proper.
Please refer this for sending tweet:
Twitter4J
Also check my code below to understand more on how to handle twitter error response also.
Code:
private final TwDialogListener mTwLoginDialogListener = new TwDialogListener() {
#Override
public void onComplete(String value) {
//Toast.makeText(getApplicationContext(), "Login successfull", Toast.LENGTH_SHORT).show();
try {
StatusUpdate status = new StatusUpdate("Posting from Twitter application...");
//status.media(new File(sPhotoPATH));
mTwitter.updateStatus(status);
//Toast.makeText(getApplicationContext(), "Login successfull", Toast.LENGTH_SHORT).show();
//getFriendListForApp();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Fail to connect Twitter", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
//getFriendListForApp();
}
#Override
public void onError(String value) {
Toast.makeText(MainActivity.this, "Fail to connect Twitter", Toast.LENGTH_LONG).show();
finish();
}
};
and another is:
public void updateStatus(final StatusUpdate status) throws Exception {
mProgressDlg.setMessage("Posting...");
mProgressDlg.show();
new Thread(new Runnable() {
#Override
public void run() {
int i = 0;
try {
mTwitter.updateStatus(status);
i = 0;
} catch (TwitterException e) {
e.printStackTrace();
System.out.println("Not Posted: In Catch");
message = e.getErrorMessage();
System.out.println("MESSAGE:::: "+message);
//asdasd
//Toast.makeText(context, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
//e.getMessage();
i= 1;
}
mPostHandler.sendEmptyMessage(i);
}
}).start();
}
Please let me know if you have any doubt from this.
Enjoy Coding... :)
I have a problem with inviting firend by facebook api to my app. This is my method:
private void inviteFromFacebook(Activity activity, List<GraphUser> list) {
for(int i=0; i<list.size(); i++) {
//TODO post invite to friends wall
// Log.v("MainActivity", "user id: " + user.getId());
if(list == null || list.size() == 0)
return;
Bundle parameters = new Bundle();
String friendsIdsInFormat = "";
friendsIdsInFormat = friendsIdsInFormat + list.get(i).getId();
parameters.putString("to", friendsIdsInFormat);
parameters.putString( "message", "Use my app!");
Facebook mFacebook = new Facebook( getResources().getString(R.string.facebook_app_id));
// Show dialog for invitation
mFacebook.dialog(activity, "apprequests", parameters, new Facebook.DialogListener() {
#Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
}
#Override
public void onCancel() {
// TODO Auto-generated method stub
}
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
#Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
});
}
}
Everyting is ok, but I want to send invitation to many frieds, so in this codes I show one dialog for every person. How can I show only one dialog, but with many friends? This is possible or I must for every friend show dialog?
You can send a comma delimited list in the "to" field, like "123,456,789".
Be careful about sending too many requests though, you don't want to be identified as a spam app.
I want to post image along with text caption via facebook SDK.
I am referring to the solution posted here.
Android post picture to Facebook wall
However, I am getting the following error.
FATAL EXCEPTION: main
java.lang.NullPointerException
at java.net.URLDecoder.decode(URLDecoder.java:104)
at java.net.URLDecoder.decode(URLDecoder.java:48)
at com.facebook.android.Util.openUrl(Util.java:173)
at com.facebook.android.Facebook.request(Facebook.java:751)
at com.xxx.yyy.gui.share.ShareDialogFactory.shareThroughFacebook(ShareDialogFactory.java:170)
I had verified my code against the previous posted solution.
private static void shareThroughFacebook(final Context context, final File file, final int heartbeatForShare) {
final Facebook facebook = new Facebook("285243934881501");
// Login.
facebook.authorize((Activity)context, new String[] { "publish_stream" }, new DialogListener() {
#Override
public void onComplete(Bundle values) {
android.util.Log.i("CHEOK", "onComplete");
}
#Override
public void onFacebookError(FacebookError error) {
android.util.Log.i("CHEOK", "onFacebookError");
}
#Override
public void onError(DialogError e) {
android.util.Log.i("CHEOK", "onError");
}
#Override
public void onCancel() {
android.util.Log.i("CHEOK", "onCancel");
}
});
android.util.Log.i("CHEOK", "STEP 1");
final byte[] data = JPEG2ByteArray(file);
final Bundle bundle = new Bundle();
bundle.putString(Facebook.TOKEN, facebook.getAccessToken());
android.util.Log.i("CHEOK", "data length is " + data.length);
bundle.putByteArray("picture", data);
bundle.putString("message", "this-is-message");
bundle.putString("caption", "this-is-caption");
// I can reach till here!
android.util.Log.i("CHEOK", "STEP 2");
try {
// NPE happens right here!!!
facebook.request("me/photos", bundle, "POST");
} catch (FileNotFoundException e1) {
android.util.Log.i("CHEOK", "FileNotFoundException");
e1.printStackTrace();
} catch (MalformedURLException e1) {
android.util.Log.i("CHEOK", "MalformedURLException");
e1.printStackTrace();
} catch (IOException e1) {
android.util.Log.i("CHEOK", "IOException");
e1.printStackTrace();
}
android.util.Log.i("CHEOK", "STEP 3");
}
I can confirm my byte array is non-zero length. I do not receive any callback during authorize, not sure whether this is correct behaviour. Note, the code shareThroughFacebook is invoked from a Dialog.
Is there any other steps I had missed out?
I have a problem. I want to use the facebook api and make a post to my wall without calling a dialog. Basically I have an app and I want people to be able to share the app, so I want to have a specific message to post. I keep getting a response of "Method not implemented". Heres the code for the post.
//I tried this also ->>String path = "http://graph.facebook.com/me/feed";
String path = "https://api.facebook.com/method/stream.publish";
Bundle b = new Bundle();
//And i tried this -> b.putString("access_token",facebook.getAccessToken());
b.putString("message", "this is just a test...");
try {
String ret = facebook.request(path, b);
Toast.makeText(fmasterActivity.this, ret, Toast.LENGTH_LONG).show();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I am assuming that you are doing that bit of code after the user successfully authenticates?
This bit of code worked for me:
private Facebook mFacebook;
private AsyncFacebookRunner mAsyncRunner;
private void onFacebookShare() {
mFacebook = new Facebook();
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
SessionEvents.addAuthListener(new SampleAuthListener());
SessionEvents.addLogoutListener(new SampleLogoutListener());
}
private void postToFBWall() {
if(mFacebook.isSessionValid()){
shareVideoOnFB();
} else {
showDialog(DIALOG_FBOOK_LOGIN);
}
}
public void shareVideoOnFB(){
Bundle params = new Bundle();
params.putString("message", "This string will appear as the status message");
params.putString("link", "This is the URL to go to");
params.putString("name", "This will appear beside the picture");
params.putString("caption", "This will appear under the title");
params.putString("description", "This will appear under the caption");
params.putString("picture", "This is the image to appear in the post");
mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {
public void onMalformedURLException(MalformedURLException e) {}
public void onIOException(IOException e) {}
public void onFileNotFoundException(FileNotFoundException e) {}
public void onFacebookError(FacebookError e) {}
public void onComplete(String response) {
logoutFacebook();
}
});
Toast.makeText(ShareActivity.this, "Posting to your Wall...", Toast.LENGTH_SHORT).show();
}
You can call onFacebookShare() in your activity's onCreate(), and then when the user presses whatever to indicate that s/he wants to share on Facebook, call postToFBWall(). Of course you have to add in handling to show the login dialog.