2013-05-09 52 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