ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Google Android API PlusClient writeMoment无所作为

2019-10-11 18:35:41  阅读:209  来源: 互联网

标签:android google-plus


为了在android应用中实现社交功能,我尝试使用“ PlusClient”类的“ writeMoment”方法,但没有任何反应.我能够与“ PlusClient”成功建立连接,并使用我的应用编写深层链接.

这是我打开Goog​​le连接时的代码:

monPlusClient = new PlusClient.Builder(this,
            new GooglePlayServicesClient.ConnectionCallbacks() {

                @Override
                public void onConnected() {
                    plusencours = false;
                    String accountName = monPlusClient.getAccountName();
                    // We've resolved any connection errors.
                    Toast.makeText(
                            ActiviteAfficher.this,
                            accountName
                                    + " "
                                    + ActiviteAfficher.this
                                            .getResources()
                                            .getString(
                                                    R.string.texteconnexion),
                            Toast.LENGTH_LONG).show();
                    // Log.d(TAG_DEBUG, accountName + " connected");
                }

                @Override
                public void onDisconnected() {
                    plusencours = false;
                    // Log.d(TAG_DEBUG, "disconnected");
                }

            }, new GooglePlayServicesClient.OnConnectionFailedListener() {

                @Override
                public void onConnectionFailed(ConnectionResult resultat) {
                    if (resultat.hasResolution()) {
                        try {
                            resultat.startResolutionForResult(
                                    ActiviteAfficher.this,
                                    REQUEST_CODE_RESOLVE_ERR);
                        } catch (SendIntentException e) {
                            plusencours = true;
                            monPlusClient.connect();
                        }
                    }
                    // Save the result and resolve the connection failure
                    // upon a user click.
                    mConnectionResult = resultat;
                }

            })
            .setVisibleActivities("http://schemas.google.com/AddActivity",
                    "http://schemas.google.com/DiscoverActivity")
            .setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE).build();

这是我使用“ writeMoment”时的代码:

ItemScope target = new ItemScope.Builder()
                .setId(monSujet.getMid())
                .setName(
                        monSujet.getName() + " - "
                                + monSujet.getNotablename())
                .setDescription(dialoguedescription).setImage(urlimage)
                .setType("http://schema.org/Person").build();
        Moment moment = new Moment.Builder()
                .setType("http://schemas.google.com/AddActivity")
                .setTarget(target).build();
        if (monPlusClient.isConnected()) {
            monPlusClient.writeMoment(moment);
        }

对我来说,了解logcat很难:

05-09 12:00:32.380: I/ElegantRequestDirector(27290): I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
05-09 12:00:32.380: I/ElegantRequestDirector(27290): Retrying request
05-09 12:00:33.000: E/Volley(27290): [3428] BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/plus/v1/people/me/moments/vault
05-09 12:00:33.050: D/SyncManager(295): failed sync operation XXXXXXX@gmail.com (com.google), com.google.android.gms.plus.action, USER, earliestRunTime 140603923, SyncResult: stats [ numIoExceptions: 1]
05-09 12:00:33.050: D/SyncSetupManager(16157): setState: sync = true, wantedSyncState = true
05-09 12:00:33.090: D/SyncSetupManager(16157): Enabling sync

解决方法:

如果您在编写应用程序活动时调试问题时遇到问题,则应尝试为GooglePlusPlatform启用调试功能:

adb shell setprop log.tag.GooglePlusPlatform VERBOSE

在此也进行了说明-https://developers.google.com/+/mobile/android/getting-started#frequently_asked_questions

在启用调试的情况下运行代码会将以下内容写入logcat:

D/GooglePlusPlatform(8133): Unexpected response code (400) when requesting: writeMoment
D/GooglePlusPlatform(8133): Error response: {
D/GooglePlusPlatform(8133):  "error": {
D/GooglePlusPlatform(8133):   "errors": [
D/GooglePlusPlatform(8133):    {
D/GooglePlusPlatform(8133):     "domain": "global",
D/GooglePlusPlatform(8133):     "reason": "badRequest",
D/GooglePlusPlatform(8133):     "message": "Missing metadata field: http://schema.org/url."
D/GooglePlusPlatform(8133):    }
D/GooglePlusPlatform(8133):   ],
D/GooglePlusPlatform(8133):   "code": 400,
D/GooglePlusPlatform(8133):   "message": "Missing metadata field: http://schema.org/url."
D/GooglePlusPlatform(8133):  }
D/GooglePlusPlatform(8133): }

如果不提供具有适当标记(而不是显式名称和描述)的公共目标URL,则不能提供Person对象.使用http://schema.org/Thing而不是http://schema.org/Person运行代码对我来说很有效.

标签:android,google-plus
来源: https://codeday.me/bug/20191011/1894753.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有