草庐IT

Android IAB 错误 - 需要身份验证

coder 2023-12-21 原文

我在我的应用程序中测试 In App Billing ()v3 时遇到问题,我无法使用测试帐户购买任何东西。它总是向我显示带有

的 Play 商店对话框
"Error Authentication is required. You must log in with your Google Account"

我只能毫无问题地购买保留项“android.test.purchased”并使用它。

IAB 开始:

private static final int REQ_CODE_BUY = 51667;
    private static final String buyFile = "bought";

    private Activity activity;
    private ProgressDialog pD;
    private IInAppBillingService mService;
    private ServiceConnection mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, 
                IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
        }
    };

    public IABHelper(Activity activity, ProgressDialog pD){
        this.activity = activity;
        this.pD = pD;
    }

    public void start(){
        Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        activity.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    }

    public void destroy(){
        if (mService != null) {
            activity.unbindService(mServiceConn);
        }   
    }

IAB 购买和消费:

public void buy(String sku){
        try {
            Bundle buyIntentBundle = mService.getBuyIntent(3, activity.getPackageName(), sku, "inapp", devPayload);
            //Bundle buyIntentBundle = mService.getBuyIntent(3, activity.getPackageName(), "android.test.purchased", "inapp", devPayload);

            PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
            if(pendingIntent != null){
                activity.startIntentSenderForResult(pendingIntent.getIntentSender(), REQ_CODE_BUY, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
                pD.show();
            }
            else{
                Toast.makeText(activity, R.string.error, Toast.LENGTH_LONG).show();
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (SendIntentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void consume(final String purchaseToken){
        Thread consumeThread = new Thread(new Runnable(){

            @Override
            public void run() {
                try {
                    int response = mService.consumePurchase(3, activity.getPackageName(), purchaseToken);
                    //int response = mService.consumePurchase(3, activity.getPackageName(), "inapp:com.mumble.artplace:android.test.purchased");
                    Log.d("response", Integer.toString(response));
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
        consumeThread.start();
    }

处理购买响应:

    public void resolveResponse(int requestCode, int resultCode, Intent data){
        if(requestCode == REQ_CODE_BUY){
            if(resultCode == Activity.RESULT_OK){
                int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
                String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
                String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");

                JSONObject jData;
                try {
                    if(responseCode == 0){
                        jData = new JSONObject(purchaseData);
                        String purchaseToken = jData.getString("purchaseToken");
                        String developerPayload = jData.getString("developerPayload");
                        if(developerPayload.equals(devPayload))){
                            consume(purchaseToken);
                        }
                    }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                pD.dismiss();
            }
            else{
                if(resultCode == Activity.RESULT_CANCELED){
                    pD.dismiss();
                }
            }
        }
    }

当发生这种情况并且我单击“确定”时,它只返回一个 responseCode RESULT_CANCEL 和一个带有空额外内容的 Intent。 我已经尝试从我的设备中删除所有帐户,只留下开发人员帐户,只留下测试帐户,并尝试使用其他手机但没有成功。我真的不知道我哪里错了... 请帮助我,谢谢

最佳答案

Soomla IAB error while purchasing in Game on Android 这是我的问题,我认为是同样的问题,所以, 问题出在 Google 开发者控制台上,为了购买,您必须发布 apk,即使它是 Beta 或 Alpha,之后,您可以使用测试人员批准的帐户进行测试。

关于Android IAB 错误 - 需要身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27920743/

有关Android IAB 错误 - 需要身份验证的更多相关文章

  1. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  2. ruby-on-rails - 如何验证 update_all 是否实际在 Rails 中更新 - 2

    给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru

  3. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  4. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  5. ruby-on-rails - 如果为空或不验证数值,则使属性默认为 0 - 2

    我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val

  6. ruby-on-rails - 如何验证非模型(甚至非对象)字段 - 2

    我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss

  7. ruby - rspec 需要 .rspec 文件中的 spec_helper - 2

    我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只

  8. ruby - 如何在 Lion 上安装 Xcode 4.6,需要用 RVM 升级 ruby - 2

    我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121

  9. ruby-on-rails - 如何将验证与模型分开 - 2

    我有一些非常大的模型,我必须将它们迁移到最新版本的Rails。这些模型有相当多的验证(User有大约50个验证)。是否可以将所有这些验证移动到另一个文件中?说app/models/validations/user_validations.rb。如果可以,有人可以提供示例吗? 最佳答案 您可以为此使用关注点:#app/models/validations/user_validations.rbrequire'active_support/concern'moduleUserValidationsextendActiveSupport:

  10. ruby-on-rails - 跳过状态机方法的所有验证 - 2

    当我的预订模型通过rake任务在状态机上转换时,我试图找出如何跳过对ActiveRecord对象的特定实例的验证。我想在reservation.close时跳过所有验证!叫做。希望调用reservation.close!(:validate=>false)之类的东西。仅供引用,我们正在使用https://github.com/pluginaweek/state_machine用于状态机。这是我的预订模型的示例。classReservation["requested","negotiating","approved"])}state_machine:initial=>'requested

随机推荐