I have created a facebook event with my android coding and now I want to invite friends to it.
Below is my code to invite friends:
private void inviteFriends()
{
try
{
Bundle params = new Bundle();
params.putString("title", "invite friends");
params.putString("message", "come join us!");
facebook.dialog(this, "apprequests", params, new DialogListener() {
#Override
public void onComplete(Bundle values) {}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
public void onComplete(String response, Object state)
{
try
{
JSONObject eventResponse = new JSONObject(response);
//event_id = event.getString("id");
Log.i(TAG, "Event Response => "+eventResponse);
Log.w("myapp", friends);
//Toast.makeText(getApplicationContext(), "New Event Created!!", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
}
}
});
}
catch (Exception e)
{
}
}
The code works up to selecting friends, the title and message comes with the friend list. I can send the invitation but no notifications are sent to selected people.
Please tell me what needs to be done. Thank you in advance!
this image.
Have you turned on the App omn Facebbok Tab in your app developer setting like this.
If don't then it will not sent notification to your friends.
Related
By facebook default message post
#SuppressWarnings("deprecation")
public void postToWall() {
// post on user's wall.
facebook.dialog(this, "feed", new DialogListener() {
#Override
public void onFacebookError(FacebookError e) {
}
#Override
public void onError(DialogError e) {
}
#Override
public void onComplete(Bundle values) {
}
#Override
public void onCancel() {
}
});
}
we can share data but want to do the same thing with regular edit text and button,Is there any way to do this,please suggest me,thanku
this will help you.
Bundle parameters = new Bundle();
parameters.putString("message", "Test");
parameters.putString("description", "topic share");
facebook.request("me");
facebook.request("me/feed", parameters, "POST");
Hello every i am working app where i have to send invitation of my app to my facebook friend.
My invitation successfully send but message is not showing to my friend whom i send the app request.
i follow this question which help in that but message is not showing to that user whom i send the app request.
here is my code:
Bundle parameters = new Bundle();
parameters.putString("to", fb2);
parameters.putString("message", "hello app ...");
Facebook mFacebook = new Facebook(APP_ID);
mFacebook.dialog(getParent(), "apprequests", parameters, new Facebook.DialogListener() {
#Override
public void onComplete(Bundle values) {
Toast.makeText(getParent(), "Invitation has been send", Toast.LENGTH_SHORT).show();
}
#Override
public void onCancel() {
}
#Override
public void onFacebookError(FacebookError e) {
}
#Override
public void onError(DialogError e) {
}
});
I have been struggling with android and the Facebook's graph API and I'm sure this is a piece of cake for intermediate programmers. What I want is a very simple Android application that logs in a user to Facebook, get the users consent to access information and finally to seamlessly query the graph API to get the users friends. I mention the work seamless because I have seen many sample applications that require the user to push a "get friends" button but I do not want that. I wish to extract the users friends without requiring him to push anything.
I have pasted the code below. I am able to to log-in and grant permission to my application. Next, I expect it to display my friends but it just directs me to a blank page. The problem might be that I am accessing the graph API in the wrong place because the Logcat does not contain the messages I print before and after the request. Could you please help me.
public class FacebookLogin extends Activity {
Facebook mFacebook = new Facebook("XXXXXXXXXXXX");
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
View linearLayout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
linearLayout = findViewById(R.id.main_layout);
mFacebook.authorize(this, new DialogListener() {
#Override
public void onComplete(Bundle values)
{
Log.d("Facebook-Example-Friends Request", "Started API request");
mAsyncRunner.request("me/friends", new FriendsRequestListener());
Log.d("Facebook-Example-Friends Request", "Finished API request");
}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
public class FriendsRequestListener implements RequestListener
{
/**
* Called when the request to get friends has been completed.
* Retrieve, parse and display the JSON stream.
*/
public void onComplete(final String response)
{
Log.d("Facebook-Example-Friends Request", "FriendsListenerOnComplete");
try
{
JSONObject json = Util.parseJson(response);
final JSONArray friends = json.getJSONArray("data");
FacebookLogin.this.runOnUiThread(new Runnable()
{
public void run()
{
int l = (friends != null ? friends.length() : 0);
for (int i=0; i<l; i++)
{
try
{
JSONObject o = friends.getJSONObject(i);
TextView tv = new TextView(FacebookLogin.this);
tv.setText(o.getString("name"));
((LinearLayout) linearLayout).addView(tv);
}
catch(JSONException e)
{
Toast.makeText(getApplicationContext(), "JSON parsing error", Toast.LENGTH_LONG);
}
}
}
});
}
catch(JSONException e)
{
Log.d("Facebook-Example-Friends Request", "JSON Error in response");
}
catch(FacebookError e)
{
Log.d("Facebook-Example-Friends Request", "Facebook Error in response");
}
}
}
}
i think you see this answer you got some idea..
Facebook/Twitter Integration in my android application
and
http://android-sample-solution.blogspot.com
i am trying to publish something on my wall. i am using this code, called by OnClickListener of a Button
public void postOnWall(String msg) {
mFacebook.authorize(this,new String[] {"publish_stream", "read_stream", "offline_access"},
new DialogListener() {
public void onError(DialogError e) {
}
public void onFacebookError(FacebookError e) {
}
public void onCancel() {
}
public void onComplete(Bundle values) {
}
}
);
Log.d("Tests", "Testing graph API wall post");
try {
Bundle parameters = new Bundle();
parameters.putString("message", msg);
parameters.putString("description", "test test test");
String response = mFacebook.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} catch(Exception e) {
e.printStackTrace();
}
}
The response string however reads
{"error":{"type":"OAuthException","message":"An active access token must be used to query information about the current user."}}
Also, the Dialog that should be requesting permissions never stays. it starts loading, but then dissapears.
It seems like you haven't properly authenticated the user.
I'm not sure if you just left out that part of your code or you're not doing it at all but I would take a look at the example provided with the API.
I want my android application to automatically post a preset message when the user click on a button. The preset message will be set by the user, so I am guessing that is not a violation of Facebook policies. How do I do this?
private static final String[] PERMISSIONS =
new String[] {"publish_stream", "read_stream", "offline_access"};
Facebook authenticatedFacebook = new Facebook(APP_ID);
postButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
authenticatedFacebook.authorize(Tests.this, PERMISSIONS,
new TestPostListener());
}
});
public class TestPostListener implements DialogListener {
public void onComplete(Bundle values) {
try {
Log.d("Tests", "Testing request for 'me'");
String response = authenticatedFacebook.request("me");
JSONObject obj = Util.parseJson(response);
Log.d("Tests", "Testing graph API wall post");
Bundle parameters = new Bundle();
parameters.putString("message", "Amit Siddhpura");
parameters.putString("description", "Hi Mr. Amit Siddhpura");
response = authenticatedFacebook.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
} catch (Throwable e) {
e.printStackTrace();
}
}
public void onCancel() {
}
public void onError(DialogError e) {
e.printStackTrace();
}
public void onFacebookError(FacebookError e) {
e.printStackTrace();
}
}
You have to create Application on Facebook
And get authenticate from user, then you can get a access_token to post some message through Graph API
I think your application have to request extended permissions : publish_stream, offline_access
There is Facebook-Android-SDK source code on github, you can refer it.
http://developers.facebook.com/docs/guides/mobile
http://www.androidpeople.com/android-facebook-api-example-using-fbrocket/