繁体   English   中英

Android Google+问题

[英]Android Google+ issues

我想通过我的应用在google-plus上发帖。 我正在为此使用此代码,但是它无法正常工作,给了我无法张贴消息的消息,并且我也不确定我将在哪里使用我的clientId?。请帮助我。

public class MainActivity extends Activity implements OnClickListener,
ConnectionCallbacks, OnConnectionFailedListener {
    private static final String TAG = "ExampleActivity";
    private static final int REQUEST_CODE_RESOLVE_ERR = 9000;

    private ProgressDialog mConnectionProgressDialog;
    private PlusClient mPlusClient;
    private ConnectionResult mConnectionResult;
    private Button shareButton=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        shareButton=(Button)findViewById(R.id.share_button);
        shareButton.setOnClickListener(this);

        mPlusClient = new PlusClient.Builder(this, this, this)
        .setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity")
        .setScopes(Scopes.PLUS_LOGIN)  // recommended login scope for social features
        // .setScopes("profile")       // alternative basic login scope
        .build();
        // Progress bar to be displayed if the connection failure is not resolved.
        mConnectionProgressDialog = new ProgressDialog(this);
        mConnectionProgressDialog.setMessage("Signing in...");

    }

    @Override
    protected void onStart() {
        super.onStart();
        mPlusClient.connect();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mPlusClient.disconnect();
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        if (mConnectionProgressDialog.isShowing()) {
            // The user clicked the sign-in button already. Start to resolve
            // connection errors. Wait until onConnected() to dismiss the
            // connection dialog.
            if (result.hasResolution()) {
                try {
                    result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
                } catch (SendIntentException e) {
                    mPlusClient.connect();
                }
            }
        }
        // Save the result and resolve the connection failure upon a user click.
        mConnectionResult = result;
    }

    @Override
    protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
        if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
            mConnectionResult = null;
            mPlusClient.connect();
        }
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        String accountName = mPlusClient.getAccountName();
        Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onDisconnected() {
        Log.d(TAG, "disconnected");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.share_button:
             Intent shareIntent = new PlusShare.Builder(this)
              .setType("text/plain")
              .setText("Welcome to the Google+ platform.")
              .setContentUrl(Uri.parse("https://developers.google.com/+/"))
              .getIntent();

          startActivityForResult(shareIntent, 0);
            break;
        }

    }
}

提前致谢

您不需要在应用程序中的任何位置都具有客户端ID,该ID是从应用程序包名称和签名密钥的SHA1推断出来的(这就是为什么它在API控制台中要求这些ID)。 但是,您无需登录或输入任何密钥即可进行您正在执行的基本共享。 为了进行测试,您可能希望删除所有PlusClient /登录相关代码,直到您满意为止PlusShare构建器正确创建了意图。

您可以确定使用的是最新版本的Google Play服务(4.1),然后查看是否还有任何问题? 如果是这样,您是否可以检查在logcat中是否还有其他错误详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM