2012-07-26 679 views
1

嗨我试图做一个小应用程序张贴在myfacebookwall。但状态没有更新。奇怪的是,日志猫错误显示,如果手机用来连接到Facebook的邮件的ID,而不是通过Gmail取代,但应用程序不会崩溃。
任何帮助,将不胜感激replaceContactWithContactId:contactId == 0(更新Facebook状态失败)

的代码是这样的:

package com.ketanoexample.facebooktrial; 

import java.io.IOException; 
import java.net.MalformedURLException; 

import android.app.Activity; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 

import com.facebook.android.DialogError; 
import com.facebook.android.Facebook; 
import com.facebook.android.Facebook.DialogListener; 
import com.facebook.android.FacebookError; 

public class fbshare extends Activity { 

Facebook facebook = new Facebook("425034397547522"); 
private SharedPreferences mPrefs; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.bshare_layout); 
    Button btn = (Button) findViewById(R.id.btnfb); 
    btn.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      compartirconfb(); 
     } 
    }); 

} 



public void updateStatus(String accessToken){ 
    try { 
     Bundle bundle = new Bundle(); 
     bundle.putString("message", "test status update made by gezn-Automated response app social handler"); 
     bundle.putString(Facebook.TOKEN,accessToken); 
     String response = facebook.request("me/feed",bundle,"POST"); 
     showToast("Update process complete. Respose:"+response); 
     Log.d("UPDATE RESPONSE",""+response); 
    } catch (MalformedURLException e) { 
     Log.e("MALFORMED URL",""+e.getMessage()); 
    } catch (IOException e) { 
     Log.e("IOEX",""+e.getMessage()); 
    } 
} 
private void showToast(String message){ 
    Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show(); 
} 

private void compartirconfb() { 
    // TODO Auto-generated method stub 
    /* 
    * Get existing access_token if any 
    */ 
    mPrefs = getPreferences(MODE_PRIVATE); 
    String access_token = mPrefs.getString("access_token", null); 
    long expires = mPrefs.getLong("access_expires", 0); 
    if(access_token != null) { 
     facebook.setAccessToken(access_token); 
    } 
    if(expires != 0) { 
     facebook.setAccessExpires(expires); 
    } 

    /* 
    * Only call authorize if the access_token has expired. 
    */ 
    if(!facebook.isSessionValid()) { 

    facebook.authorize(this,new String[] { "email", "publish_stream" }, new DialogListener() { 
     @Override 
     public void onComplete(Bundle values) { 
      SharedPreferences.Editor editor = mPrefs.edit(); 
      editor.putString("access_token", facebook.getAccessToken()); 
      editor.putLong("access_expires", facebook.getAccessExpires()); 
      editor.commit(); 
      updateStatus(values.getString(Facebook.TOKEN)); 

     } 

     @Override 
     public void onFacebookError(FacebookError error) {} 

     @Override 
     public void onError(DialogError e) {} 

     @Override 
     public void onCancel() {} 
    }); 
} 
} 
@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    facebook.authorizeCallback(requestCode, resultCode, data); 
} 

} 

日志猫是这样的,我注意到启用登录属实,Facebook上的SDK的Util.java,因为我不能看到之前的错误。

07-26 18:44:34.399: D/dalvikvm(5676): GC_CONCURRENT freed 405K, 45% free 3765K/6727K, external 0K/0K, paused 4ms+6ms 
07-26 18:44:43.049: D/dalvikvm(5676): GC_EXPLICIT freed 85K, 46% free 3680K/6727K, external 0K/0K, paused 83ms 
07-26 18:44:54.339: I/wpa_supplicant(1551): CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys 
07-26 18:44:54.339: V/WifiMonitor(1428): Event [CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys] 
07-26 18:44:54.339: V/WifiStateTracker(1428): New network state is DISCONNECTED 
07-26 18:44:54.349: I/wpa_supplicant(1551): CTRL-EVENT-STATE-CHANGE id=12 state=0 BSSID=00:00:00:00:00:00 
07-26 18:44:54.349: V/WifiMonitor(1428): Event [CTRL-EVENT-STATE-CHANGE id=12 state=0 BSSID=00:00:00:00:00:00] 
07-26 18:44:54.349: V/WifiStateTracker(1428): Changing supplicant state: COMPLETED ==> DISCONNECTED 
07-26 18:44:54.439: I/wpa_supplicant(1551): CTRL-EVENT-STATE-CHANGE id=12 state=2 BSSID=00:00:00:00:00:00 
07-26 18:44:54.439: V/WifiMonitor(1428): Event [CTRL-EVENT-STATE-CHANGE id=12 state=2 BSSID=00:00:00:00:00:00] 
07-26 18:44:54.439: V/WifiStateTracker(1428): Changing supplicant state: DISCONNECTED ==> SCANNING 
07-26 18:44:54.909: D/wifi(1428): wifi doCommand: ret=-1 
07-26 18:44:55.669: I/wpa_supplicant(1551): Trying to associate with 00:23:cd:1c:b7:e2 (SSID='kawsaytaraj' freq=2432 MHz) 
07-26 18:44:55.669: I/wpa_supplicant(1551): CTRL-EVENT-STATE-CHANGE id=12 state=3 BSSID=00:23:cd:1c:b7:e2 
07-26 18:44:55.679: V/WifiMonitor(1428): Event [Trying to associate with 00:23:cd:1c:b7:e2 (SSID='kawsaytaraj' freq=2432 MHz)] 
07-26 18:44:55.689: V/WifiMonitor(1428): Event [CTRL-EVENT-STATE-CHANGE id=12 state=3 BSSID=00:23:cd:1c:b7:e2] 
07-26 18:44:55.689: V/WifiStateTracker(1428): Changing supplicant state: SCANNING ==> ASSOCIATING 
07-26 18:44:56.279: I/wpa_supplicant(1551): CTRL-EVENT-STATE-CHANGE id=12 state=4 BSSID=00:23:cd:1c:b7:e2 
07-26 18:44:56.279: V/WifiMonitor(1428): Event [CTRL-EVENT-STATE-CHANGE id=12 state=4 BSSID=00:23:cd:1c:b7:e2] 
07-26 18:44:56.279: V/WifiStateTracker(1428): Changing supplicant state: ASSOCIATING ==> ASSOCIATED 
07-26 18:44:56.289: I/wpa_supplicant(1551): Associated with 00:23:cd:1c:b7:e2 
07-26 18:44:56.289: V/WifiMonitor(1428): Event [Associated with 00:23:cd:1c:b7:e2] 
07-26 18:44:56.299: I/wpa_supplicant(1551): CTRL-EVENT-STATE-CHANGE id=12 state=5 BSSID=00:00:00:00:00:00 
07-26 18:44:56.299: V/WifiMonitor(1428): Event [CTRL-EVENT-STATE-CHANGE id=12 state=5 BSSID=00:00:00:00:00:00] 
07-26 18:44:56.309: V/WifiStateTracker(1428): Changing supplicant state: ASSOCIATED ==> FOUR_WAY_HANDSHAKE 
07-26 18:44:56.350: I/wpa_supplicant(1551): CTRL-EVENT-STATE-CHANGE id=12 state=5 BSSID=00:00:00:00:00:00 
07-26 18:44:56.350: V/WifiMonitor(1428): Event [CTRL-EVENT-STATE-CHANGE id=12 state=5 BSSID=00:00:00:00:00:00] 
07-26 18:44:56.359: V/WifiStateTracker(1428): Changing supplicant state: FOUR_WAY_HANDSHAKE ==> FOUR_WAY_HANDSHAKE 
07-26 18:44:56.359: I/wpa_supplicant(1551): CTRL-EVENT-STATE-CHANGE id=12 state=6 BSSID=00:00:00:00:00:00 
07-26 18:44:56.359: V/WifiMonitor(1428): Event [CTRL-EVENT-STATE-CHANGE id=12 state=6 BSSID=00:00:00:00:00:00] 
07-26 18:44:56.369: V/WifiStateTracker(1428): Changing supplicant state: FOUR_WAY_HANDSHAKE ==> GROUP_HANDSHAKE 
07-26 18:44:56.369: I/wpa_supplicant(1551): WPA: Key negotiation completed with 00:23:cd:1c:b7:e2 [PTK=CCMP GTK=TKIP] 
07-26 18:44:56.369: V/WifiMonitor(1428): Event [WPA: Key negotiation completed with 00:23:cd:1c:b7:e2 [PTK=CCMP GTK=TKIP]] 
07-26 18:44:56.369: I/wpa_supplicant(1551): CTRL-EVENT-STATE-CHANGE id=12 state=7 BSSID=00:00:00:00:00:00 
07-26 18:44:56.369: V/WifiMonitor(1428): Event [CTRL-EVENT-STATE-CHANGE id=12 state=7 BSSID=00:00:00:00:00:00] 
07-26 18:44:56.369: V/WifiStateTracker(1428): Changing supplicant state: GROUP_HANDSHAKE ==> COMPLETED 
07-26 18:44:56.369: I/wpa_supplicant(1551): CTRL-EVENT-CONNECTED - Connection to 00:23:cd:1c:b7:e2 completed (reauth) [id=12 id_str=] 
07-26 18:44:56.369: V/WifiMonitor(1428): Event [CTRL-EVENT-CONNECTED - Connection to 00:23:cd:1c:b7:e2 completed (reauth) [id=12 id_str=]] 
07-26 18:44:56.369: V/WifiStateTracker(1428): New network state is CONNECTED 
07-26 18:44:56.379: D/WifiStateTracker(1428): Reset connections and stopping DHCP 
07-26 18:44:56.399: W/Smack/Packet(1582): notify conn break (IOEx), close connection 
07-26 18:44:56.399: D/Smack(1582): [XMPPConn] close connection, notifyClosed=false 
07-26 18:44:56.429: D/dhcpcd(6058): received SIGTERM, stopping 
07-26 18:44:56.429: D/dhcpcd(6058): deleting route 0.0.0.0/0 via 192.168.0.1 
07-26 18:44:56.429: D/dhcpcd(6058): deleting IP address 192.168.0.102/24 
07-26 18:44:56.429: D/dhcpcd(6058): executing `/system/etc/dhcpcd/dhcpcd-run-hooks', reason STOP 
07-26 18:44:56.559: D/GTalkService(1582): [GTalkConnection.21] connectionClosed: connId=22690, error=CONNECTION FAILED 
07-26 18:44:57.439: D/WifiStateTracker(1428): DHCP request started 
07-26 18:44:57.449: D/dhcpcd(6119): dhcpcd 4.0.15 starting 
07-26 18:44:57.449: D/dhcpcd(6119): hardware address = 58:17:0c:43:74:29 
07-26 18:44:57.449: D/dhcpcd(6119): executing `/system/etc/dhcpcd/dhcpcd-run-hooks', reason PREINIT 
07-26 18:44:57.469: D/dhcpcd(6119): host does not support a monotonic clock - timing can skew 
07-26 18:44:57.469: D/dhcpcd(6119): broadcasting for a lease 
07-26 18:44:57.479: D/dhcpcd(6119): sending DHCP_DISCOVER with xid 0x1c3d4b6a, next in 4.55 seconds 
07-26 18:44:57.479: D/dhcpcd(6119): offered 192.168.0.102 from 192.168.0.1 
07-26 18:44:57.479: D/dhcpcd(6119): sending DHCP_REQUEST with xid 0x1c3d4b6a, next in 4.76 seconds 
07-26 18:44:57.489: D/dhcpcd(6119): acknowledged 192.168.0.102 from 192.168.0.1 
07-26 18:44:57.489: D/dhcpcd(6119): checking 192.168.0.102 is available on attached networks 
07-26 18:44:57.489: D/dhcpcd(6119): sending ARP probe (1 of 3), next in 1.54 seconds 
07-26 18:44:59.039: D/dhcpcd(6119): sending ARP probe (2 of 3), next in 1.47 seconds 
07-26 18:44:59.379: W/WifiStateTracker(1428): Skip RssiApprox, not connected... 
07-26 18:45:00.516: D/dhcpcd(6119): sending ARP probe (3 of 3), next in 2.00 seconds 
07-26 18:45:02.379: W/WifiStateTracker(1428): Skip RssiApprox, not connected... 
07-26 18:45:02.516: D/dhcpcd(6119): leased 192.168.0.102 for 7200 seconds 
07-26 18:45:02.516: D/dhcpcd(6119): adding IP address 192.168.0.102/24 
07-26 18:45:02.519: D/dhcpcd(6119): adding route to 0.0.0.0/0 via 192.168.0.1 
07-26 18:45:02.519: D/dhcpcd(6119): executing `/system/etc/dhcpcd/dhcpcd-run-hooks', reason BOUND 
07-26 18:45:03.443: D/WifiStateTracker(1428): DHCP succeeded with lease: 7200 
07-26 18:45:03.449: V/WifiStateTracker(1428): IP configuration: ipaddr 192.168.0.102 gateway 192.168.0.1 netmask 255.255.255.0 dns1 200.87.100.10 dns2 200.87.100.40 DHCP server 192.168.0.1 lease 7200 seconds 
07-26 18:45:03.509: D/WifiWatchdogService(1428): (android.server.ServerThread) kawsaytaraj (00:23:cd:1c:b7:e2) does not require the watchdog 
07-26 18:45:03.519: D/GTalkService(1582): ##### Network broadcast (connected=true) type=WIFI, state=CONNECTED 
07-26 18:45:03.519: D/GTalkService(1582): [GTalkConnection.1] setInternalNetworkState: type=1, state=CONNECTED 
07-26 18:45:03.529: D/CMStats(5741): CONNECTIVITY_ACTION: noConnectivity = false 
07-26 18:45:03.529: D/CMStats(5741): CONNECTIVITY_ACTION: starting service 
07-26 18:45:03.559: D/CMStats(5741): User has not opted in -- skipping reporting. 
07-26 18:45:03.589: D/Tethering(1428): MasterInitialState.processMessage what=3 
07-26 18:45:03.639: I/MediaUploader(5758): No need to wake up 
07-26 18:45:04.573: D/dhcpcd(6119): sending ARP announce (1 of 2), next in 2.00 seconds 
07-26 18:45:05.049: D/dalvikvm(1582): GC_CONCURRENT freed 372K, 44% free 3827K/6791K, external 0K/512K, paused 5ms+10ms 
07-26 18:45:06.580: D/dhcpcd(6119): sending ARP announce (2 of 2) 
07-26 18:45:06.580: D/dhcpcd(6119): renew in 3596 seconds 
07-26 18:45:06.859: D/GTalkService(1582): [RosterListenerImpl] removeTalkPresence for account=1, deleted=18 
07-26 18:45:06.869: D/GTalkService(1582): [ContactPresence] removeAllContactsPresence: account=1, set null presence for 4 
07-26 18:45:07.379: D/GTalkService(1582): [RosterMgr] roster not modified 
07-26 18:45:07.409: E/TalkProvider(1582): replaceContactWithContactId: contactId==0!!! [email protected], acct=1 
07-26 18:45:07.409: E/TalkProvider(1582): insert presence failed for account=1 [email protected] client_type=0 status= cap=8 priority=0 mode=3 
07-26 18:45:07.439: D/GTalkService(1582): [OtrMgr] OTR not modified 

回答