首页 > 解决方案 > 当我运行我的项目/

问题描述

我有一个包含 API 密钥的文件,但我不断收到此错误。当我知道所有内容都正确命名并且我有一个 API 密钥时,我想不出任何理由为什么会收到一个无效的 API 密钥错误。这是我的 mainactivity.java 文件中的代码。我认为我设置图像按钮的方式可能存在问题,但我不确定并且非常困惑。任何帮助将不胜感激。

这是我在运行应用程序的模拟器上单击按钮时不断遇到的实际错误。

public class MainActivity extends AppCompatActivity {
    private RequestContext requestContext;

    ImageButton loginButton;

    @Override
    protected void onResume() {
        super.onResume();
        requestContext.onResume();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        /* Previous onCreate declarations omitted */

        // Find the button with the login_with_amazon ID
        // and set up a click handler
        //loginButton = findViewById(R.id.login_with_amazon);
        loginButton = (ImageButton) findViewById(R.id.login_with_amazon);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Toast.makeText(MainActivity.this, "it works", Toast.LENGTH_LONG).show();

                AuthorizationManager.authorize(new AuthorizeRequest
                        .Builder(requestContext)
                        .addScopes(ProfileScope.profile(), ProfileScope.postalCode())
                        .build());

            }
        });


        requestContext = RequestContext.create(this);
        requestContext.registerListener(new AuthorizeListener() {


            /* Authorization was completed successfully. */
            @Override
            public void onSuccess(AuthorizeResult result) {
                /* Your app is now authorized for the requested scopes */
            }

            /* There was an error during the attempt to authorize the
            application. */
            @Override
            public void onError(AuthError ae) {
                /* Inform the user of the error */
            }

            /* Authorization was cancelled before it could be completed. */
            @Override
            public void onCancel(AuthCancellation cancellation) {
                /* Reset the UI to a ready-to-login state */
            }

        });
    }
}

标签: android

解决方案


推荐阅读