Domanda

I want to send notification to my selected Facebook friends,According to the doc,I used following code.

private void sendNotification() {
        Bundle params = new Bundle();
        params.putString("href", "/testurl?param1=value1");
        params.putString("template", "This is a test message");
        /* make the API call */
        new Request(Session.getActiveSession(), "/me/notifications", params,
                HttpMethod.POST, new Request.Callback() {
                    public void onCompleted(Response response) {
                        /* handle the result */
                        Log.d(LOG_TAG, response.toString());
                    }
                }).executeAsync();
    }

I tried lot and found that facebook has blocked permission to post on friends wall so I have option to send notification to inform own activity with selected friends. This code is not working for me.If any one has solution please share.I will really appreciate this.Thanks

È stato utile?

Soluzione

According to documentation-

Currently, only apps on Facebook.com can use App Notifications. Notifications are only surfaced on the desktop version of Facebook.com.

So you have to have a canvas app inside facebook to send the notification.

Else, there are other different ways of sharing, have a look at this article: Sharing in Android

Edit:

Implementing /feed API-

private void publishStory() {
Session session = Session.getActiveSession();

if (session != null){

    // Check for publish permissions    
    List<String> permissions = session.getPermissions();
    if (!isSubsetOf(PERMISSIONS, permissions)) {
        pendingPublishReauthorization = true;
        Session.NewPermissionsRequest newPermissionsRequest = new Session
                .NewPermissionsRequest(this, PERMISSIONS);
    session.requestNewPublishPermissions(newPermissionsRequest);
        return;
    }

    Bundle postParams = new Bundle();
    postParams.putString("name", "Facebook SDK for Android");
    postParams.putString("caption", "Build great social apps and get more installs.");
    postParams.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
    postParams.putString("link", "https://developers.facebook.com/android");
    postParams.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

    Request.Callback callback= new Request.Callback() {
        public void onCompleted(Response response) {
            JSONObject graphResponse = response
                                       .getGraphObject()
                                       .getInnerJSONObject();
            String postId = null;
            try {
                postId = graphResponse.getString("id");
            } catch (JSONException e) {
                Log.i(TAG,
                    "JSON error "+ e.getMessage());
            }
            FacebookRequestError error = response.getError();
            if (error != null) {
                Toast.makeText(getActivity()
                     .getApplicationContext(),
                     error.getErrorMessage(),
                     Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getActivity()
                         .getApplicationContext(), 
                         postId,
                         Toast.LENGTH_LONG).show();
            }
        }
    };

    Request request = new Request(session, "me/feed", postParams, 
                          HttpMethod.POST, callback);

    RequestAsyncTask task = new RequestAsyncTask(request);
    task.execute();
}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top