Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Google Plus API集成错误未请求相应的API_Android_Google Plus_Integration - Fatal编程技术网

Android Google Plus API集成错误未请求相应的API

Android Google Plus API集成错误未请求相应的API,android,google-plus,integration,Android,Google Plus,Integration,我正在尝试在我的应用程序中实现google+,我已经提到了这一点 以下是应用程序梯度文件: dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.android.support:support-v4:22.2.0' compile 'com.google.andro

我正在尝试在我的应用程序中实现google+,我已经提到了这一点

以下是应用程序梯度文件:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.google.android.gms:play-services-base:8.4.0'

    compile 'com.google.android.gms:play-services-auth:8.4.0'
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
    compile project(':androidHorizontalListView')
    compile('com.twitter.sdk.android:twitter:1.11.0@aar') {
        transitive = true;
    }
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
}
apply plugin: 'com.google.gms.google-services'
格拉德尔项目:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'com.google.gms:google-services:2.0.0-alpha3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
Google+登录活动

public class LoginActivity extends FragmentActivity implements View.OnClickListener, IServerResponse, GoogleApiClient.OnConnectionFailedListener {

     private LinearLayout back_layout    = null;

    private ImageView googlplus_btn = null;


    //    ImageView _rightImageView;





    /**
     *
     * G+ Login
     *
     */


    private static final int RC_SIGN_IN = 9001;
    private GoogleApiClient mGoogleApiClient;
    private ProgressDialog mProgressDialog;


    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */

    @Override
    public void onStart() {
        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        // googleClient.connect();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "LoginActivity Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
                Uri.parse("android-app://com.tv.grantsource/http/host/path")
        );
        AppIndex.AppIndexApi.start(mGoogleApiClient, viewAction);


        OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
        if (opr.isDone()) {
            // If the user's cached credentials are valid, the OptionalPendingResult will be "done"
            // and the GoogleSignInResult will be available instantly.
            Log.d("LOGIN", "Got cached sign-in");
            GoogleSignInResult result = opr.get();
            handleSignInResult(result);
        } else {
            // If the user has not previously signed in on this device or the sign-in has expired,
            // this asynchronous branch will attempt to sign in the user silently.  Cross-device
            // single sign-on will occur in this branch.
            showProgressDialog();
            opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
                @Override
                public void onResult(GoogleSignInResult googleSignInResult) {
                    hideProgressDialog();
                    handleSignInResult(googleSignInResult);
                }
            });
        }
    }

    @Override
    public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "LoginActivity Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
                Uri.parse("android-app://com.tv.grantsource/http/host/path")
        );
        AppIndex.AppIndexApi.end(mGoogleApiClient, viewAction);

    }


    private void showProgressDialog() {
        if (mProgressDialog == null) {
            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setMessage("Loading...");
            mProgressDialog.setIndeterminate(true);
        }

        mProgressDialog.show();
    }

    private void hideProgressDialog() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.hide();
        }
    }


    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        // An unresolvable error has occurred and Google APIs (including Sign-In) will not
        // be available.
        Log.d("LoginActivity", "onConnectionFailed:" + connectionResult);
    }




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        //Google Plus

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        // Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this,this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();

        setContentView(R.layout.login_screen);
        sharedprefclass = new SharedprefClass(this);
        initialize();
        setonclick();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    private void initialize() {
        back_layout = (LinearLayout) findViewById(R.id.back_layout);
        googlplus_btn = (ImageView) findViewById(R.id.googlplus_btn);
        setHedder();


        }

    private void setonclick() {
        googlplus_btn.setOnClickListener(this);
        back_layout.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.googlplus_btn:
                signIn();
                break;
        }

    }

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(result);
        }
    }

    /**
     *
     * Google plus
     *
     */

    private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }
    // [END signIn]

    // [START signOut]
    private void signOut() {
        Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        // [START_EXCLUDE]
                        //  updateUI(false);
                        // [END_EXCLUDE]
                    }
                });
    }

    private void handleSignInResult(GoogleSignInResult result) {
        Log.d("LOGIN", "handleSignInResult:" + result.isSuccess());
        if (result.isSuccess()) {
            // Signed in successfully, show authenticated UI.
            GoogleSignInAccount acct = result.getSignInAccount();
      /*      mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
            updateUI(true);
      */  } else {
            // Signed out, show unauthenticated UI.
            //    updateUI(false);
        }
    }


}
是否有我没有执行的内容请告诉我是否有删除:

mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
从onCreate()的最后一行号,它将覆盖对象。

删除:

mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
从onCreate()的最后一行号开始,它将覆盖对象。

您可以这样使用:

Intent shareIntent = new PlusShare.Builder(this)
.setType("text/plain")
.setText("Android Tutorial #android #tutorial")
.setContentUrl(Uri.parse("http://androidtutorialforbeginners.com"))
.getIntent();
参考

您可以这样使用:

Intent shareIntent = new PlusShare.Builder(this)
.setType("text/plain")
.setText("Android Tutorial #android #tutorial")
.setContentUrl(Uri.parse("http://androidtutorialforbeginners.com"))
.getIntent();

参考

这可以帮助我检查一下,我已经看到了那个,但在我的案例中不起作用我猜:mGoogleApiClient=new-GoogleApiClient.Builder(this).addApi(AppIndex.API).build();从onCreate()的最后一行号开始,它将覆盖对象。@Anjalitripath我欢迎:)如果检查这个,这将对我有帮助我已经看到了那个,但在我的案例中不起作用我猜:mGoogleApiClient=new GoogleApiClient.Builder(this).addApi(AppIndex.API.build();从onCreate()的最后一行号开始,它将覆盖对象。@Anjalitripath欢迎:)