2013-05-09 45 views
2

为了实现android应用中的社交功能,我尝试使用“PlusClient”类的“writeMoment”方法,但没有任何反应。我可以通过“PlusClient”获得成功的连接,并使用我的应用程序编写深层链接帖子。Google+ android API PlusClient writeMoment什么都不做

这里是我的代码时,我打开了Google+连接:

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 [email protected] (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 

回答

4

如果您在编写应用程序活动时调试问题时遇到问题,您应该尝试使用enabli NG调试的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): } 

你不能没有提供提供一个Person对象一个具有适当标记的公共目标URL(而不是明确的名称和描述)。用http://schema.org/Thing而不是http://schema.org/Person运行您的代码为我工作。

+0

不,我得到失败的同步操作[email protected]错误,而要去谷歌玩商店的应用程序! – 2016-02-15 06:24:56