【问题标题】:Send Facebook friends notification发送 Facebook 好友通知
【发布时间】:2014-04-01 19:05:43
【问题描述】:

我想向我选择的 Facebook 朋友发送通知,根据文档,我使用了以下代码。

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();
    }

我尝试了很多,发现 Facebook 已经阻止了在朋友墙上发帖的权限,所以我可以选择发送通知来通知自己与选定朋友的活动。 此代码不适用于我。如果有人有解决方案,请分享。我将非常感激。谢谢

【问题讨论】:

  • 错误:{HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) 只有网络画布应用可以发送应用通知}}

标签: android facebook facebook-graph-api notifications facebook-android-sdk


【解决方案1】:

根据documentation-

目前,只有 Facebook.com 上的应用可以使用应用通知。通知仅在桌面版 Facebook.com 上显示。

所以你必须在 facebook 中有一个画布应用来发送通知。

还有其他不同的分享方式,看看这篇文章:Sharing in Android

编辑:

实现/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();
}
}

【讨论】:

  • 我不想使用 WebDialog 进行分享实际上我必须从我的应用程序向炸薯条发送通知/消息,所以我更喜欢 Graph API
  • 你也可以使用Graph API,使用API​​/feed并给出相关参数
  • 请参阅我在答案中提供的链接中的文章“使用 API 调用共享链接”,该链接使用 /feed api 并发布提要
  • 我已经实现了这个,现在得到这个错误 {Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 100, errorType: OAuthException, errorMessage: (#100) 你尚未为此操作类型 (624207847633662) 启用用户消息。请在 App Dashboard} 中更新您的 Open Graph 设置,isFromCache:false}
  • 您正在使用开放图故事。您是否在应用设置中添加了任何打开图形操作?我已经添加了代码来实现简单的发布。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多