0

我正在通过意图在 Google plus 上发布图像(我正在捕获我的设备的图像),这意味着我没有使用 outh 身份验证,但是在发布图像应用程序时出现错误,我的日志如下

01-05 20:12:14.021: E/HttpTransaction(6230): HttpOperation failed com.google.android.apps.plus.api.SnapToPlaceOperation@47da30a8
01-05 20:12:14.021: E/HttpTransaction(6230): java.lang.RuntimeException: Cannot obtain authentication token
01-05 20:12:14.021: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.ApiaryHttpRequestConfiguration.addHeaders(ApiaryHttpRequestConfiguration.java:59)
01-05 20:12:14.021: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpTransaction.<init>(HttpTransaction.java:298)
01-05 20:12:14.021: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpOperation.start(HttpOperation.java:199)
01-05 20:12:14.021: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpOperation.start(HttpOperation.java:179)
01-05 20:12:14.021: E/HttpTransaction(6230):    at com.google.android.apps.plus.phone.LocationController$2.run(LocationController.java:403)
01-05 20:12:14.021: E/HttpTransaction(6230): Caused by: com.google.android.apps.plus.network.NetworkException: Cannot get auth token
01-05 20:12:14.021: E/HttpTransaction(6230):    at com.google.android.apps.plus.util.AccountsUtil.getAuthToken(AccountsUtil.java:141)
01-05 20:12:14.021: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.ApiaryAuthDataFactory$ApiaryAuthDataImpl.getAuthToken(ApiaryAuthDataFactory.java:72)
01-05 20:12:14.021: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.ApiaryHttpRequestConfiguration.addHeaders(ApiaryHttpRequestConfiguration.java:56)
01-05 20:12:14.021: E/HttpTransaction(6230):    ... 4 more
01-05 20:12:14.021: E/HttpTransaction(6230): Caused by: com.google.android.apps.plus.network.NetworkException: Cannot get auth token
01-05 20:12:14.021: E/HttpTransaction(6230):    at com.google.android.apps.plus.util.AccountsUtil.getAuthToken(AccountsUtil.java:137)
01-05 20:12:14.021: E/HttpTransaction(6230):    ... 6 more
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
01-05 20:12:23.704: E/HttpTransaction(6230): HttpOperation failed com.google.android.apps.plus.api.SnapToPlaceOperation@47ff4940
01-05 20:12:23.704: E/HttpTransaction(6230): java.lang.RuntimeException: Cannot obtain authentication token
01-05 20:12:23.704: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.ApiaryHttpRequestConfiguration.addHeaders(ApiaryHttpRequestConfiguration.java:59)
01-05 20:12:23.704: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpTransaction.<init>(HttpTransaction.java:298)
01-05 20:12:23.704: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpOperation.start(HttpOperation.java:199)
01-05 20:12:23.704: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpOperation.start(HttpOperation.java:179)
01-05 20:12:23.704: E/HttpTransaction(6230):    at com.google.android.apps.plus.phone.LocationController$2.run(LocationController.java:403)
01-05 20:12:23.704: E/HttpTransaction(6230): Caused by: com.google.android.apps.plus.network.NetworkException: Cannot get auth token
01-05 20:12:23.704: E/HttpTransaction(6230):    at com.google.android.apps.plus.util.AccountsUtil.getAuthToken(AccountsUtil.java:141)
01-05 20:12:23.704: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.ApiaryAuthDataFactory$ApiaryAuthDataImpl.getAuthToken(ApiaryAuthDataFactory.java:72)
01-05 20:12:23.704: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.ApiaryHttpRequestConfiguration.addHeaders(ApiaryHttpRequestConfiguration.java:56)
01-05 20:12:23.704: E/HttpTransaction(6230):    ... 4 more
01-05 20:12:23.704: E/HttpTransaction(6230): Caused by: com.google.android.apps.plus.network.NetworkException: Cannot get auth token
01-05 20:12:23.704: E/HttpTransaction(6230):    at com.google.android.apps.plus.util.AccountsUtil.getAuthToken(AccountsUtil.java:137)
01-05 20:12:23.704: E/HttpTransaction(6230):    ... 6 more
01-05 20:12:23.767: D/WifiService(2478): releaseWifiLockLocked: WifiLock{NetworkLocationProvider type=2 binder=android.os.Binder@480c9f98}
01-05 20:12:23.782: D/GoogleLoginService(2665): onBind: Intent { act=android.accounts.AccountAuthenticator cmp=com.google.android.gsf/.loginservice.GoogleLoginService }
01-05 20:12:23.814: E/AudioTrack(2478): getAudioMode[0]
01-05 20:12:23.896: D/WifiService(2478): acquireWifiLockLocked: WifiLock{NetworkLocationProvider type=2 binder=android.os.Binder@480c9f98}
01-05 20:12:24.173: E/HttpTransaction(6230): HttpOperation failed com.google.android.apps.plus.api.SnapToPlaceOperation@48004500
01-05 20:12:24.173: E/HttpTransaction(6230): java.lang.RuntimeException: Cannot obtain authentication token
01-05 20:12:24.173: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.ApiaryHttpRequestConfiguration.addHeaders(ApiaryHttpRequestConfiguration.java:59)
01-05 20:12:24.173: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpTransaction.<init>(HttpTransaction.java:298)
01-05 20:12:24.173: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpOperation.start(HttpOperation.java:199)
01-05 20:12:24.173: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpOperation.start(HttpOperation.java:179)
01-05 20:12:24.173: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.HttpOperation$1.run(HttpOperation.java:294)
01-05 20:12:24.173: E/HttpTransaction(6230):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
01-05 20:12:24.173: E/HttpTransaction(6230):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
01-05 20:12:24.173: E/HttpTransaction(6230):    at java.lang.Thread.run(Thread.java:1096)
01-05 20:12:24.173: E/HttpTransaction(6230): Caused by: com.google.android.apps.plus.network.NetworkException: Cannot get auth token
01-05 20:12:24.173: E/HttpTransaction(6230):    at com.google.android.apps.plus.util.AccountsUtil.getAuthToken(AccountsUtil.java:141)
01-05 20:12:24.173: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.ApiaryAuthDataFactory$ApiaryAuthDataImpl.getAuthToken(ApiaryAuthDataFactory.java:72)
01-05 20:12:24.173: E/HttpTransaction(6230):    at com.google.android.apps.plus.network.ApiaryHttpRequestConfiguration.addHeaders(ApiaryHttpRequestConfiguration.java:56)
01-05 20:12:24.173: E/HttpTransaction(6230):    ... 7 more
01-05 20:12:24.173: E/HttpTransaction(6230): Caused by: com.google.android.apps.plus.network.NetworkException: Cannot get auth token
01-05 20:12:24.173: E/HttpTransaction(6230):    at com.google.android.apps.plus.util.AccountsUtil.getAuthToken(AccountsUtil.java:137)
01-05 20:12:24.173: E/HttpTransaction(6230):    ... 9 more
01-05 20:12:24.396: E/MediaPlayer(2478): Unable to to create media player
*****************************************************************************************************************************************************************************
01-05 20:12:34.107: E/AndroidRuntime(6230): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.apps.plus/com.google.android.apps.plus.phone.EditAudienceActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.android.apps.plus.views.EsListView
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.os.Looper.loop(Looper.java:123)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.app.ActivityThread.main(ActivityThread.java:4627)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at java.lang.reflect.Method.invokeNative(Native Method)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at java.lang.reflect.Method.invoke(Method.java:521)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at dalvik.system.NativeStart.main(Native Method)
01-05 20:12:34.107: E/AndroidRuntime(6230): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.android.apps.plus.views.EsListView
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at com.google.android.apps.plus.fragments.EditAudienceFragment.onCreateView(EditAudienceFragment.java:414)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:846)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1160)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:200)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.app.Activity.setContentView(Activity.java:1647)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at com.google.android.apps.plus.phone.EditAudienceActivity.onCreate(EditAudienceActivity.java:46)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-05 20:12:34.107: E/AndroidRuntime(6230):     ... 11 more
01-05 20:12:34.107: E/AndroidRuntime(6230): Caused by: java.lang.reflect.InvocationTargetException
01-05 20:12:34.107: E/AndroidRuntime(6230):     at com.google.android.apps.plus.views.EsListView.<init>(EsListView.java:25)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at java.lang.reflect.Constructor.constructNative(Native Method)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
01-05 20:12:34.107: E/AndroidRuntime(6230):     ... 30 more
01-05 20:12:34.107: E/AndroidRuntime(6230): Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/scrollbar_handle_vertical.9.png from drawable resource ID #0x0
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.content.res.Resources.loadDrawable(Resources.java:1714)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.widget.AbsListView.<init>(AbsListView.java:630)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.widget.ListView.<init>(ListView.java:230)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.widget.ListView.<init>(ListView.java:226)
01-05 20:12:34.107: E/AndroidRuntime(6230):     ... 34 more
01-05 20:12:34.107: E/AndroidRuntime(6230): Caused by: java.io.FileNotFoundException: res/drawable-hdpi/scrollbar_handle_vertical.9.png
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.content.res.AssetManager.openNonAssetNative(Native Method)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.content.res.AssetManager.openNonAsset(AssetManager.java:405)
01-05 20:12:34.107: E/AndroidRuntime(6230):     at android.content.res.Resources.loadDrawable(Resources.java:1706)
01-05 20:12:34.107: E/AndroidRuntime(6230):     ... 38 more

我正在使用的代码如下

if(share!=null && share.equalsIgnoreCase("Share with GooglePlus")){
                Uri uri =Uri.parse(url);
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("image/png");
                intent.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(Intent.createChooser(intent , "Send                      
                                                                               options"));
}

感谢所有建议谢谢

已编辑

我正在截取设备的屏幕截图并将其发布在 google plus 上,我使用了你的代码,我得到了异常 FileNotFoundException() 并且 getAbsolutePath() 方法对于 String 类型未定义,我的代码如下所示,请建议我在代码中更正

包 com.testproject;

import java.io.File;
import java.io.FileNotFoundException;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;

public class TestProjectActivity extends Activity {

    private Button share_btn = null; 
    private String url=null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        share_btn = (Button)findViewById(R.id.share_btn);
        share_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent=new Intent(TestProjectActivity.this,ShareDialogActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);    
                startActivityForResult(intent, 1);  
            }
        });
    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        String url =takeScreenShot();
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
        case 1:
            String share = data.getExtras().getString("NAME");
            if(share!=null && share.equalsIgnoreCase("Share with Instagram")){
                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("image/jpg");
                i.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
                startActivity(Intent.createChooser(i, "Share Image"));
            }

            if(share!=null && share.equalsIgnoreCase("Share with GooglePlus")){
                Intent shareIntent = new Intent(Intent.ACTION_SEND);
                File tmpFile = new File(url);
                String photoUri=null;
                photoUri = url.getAbsolutePath();
                try {
                    photoUri = MediaStore.Images.Media.insertImage(
                            getContentResolver(), tmpFile.getAbsolutePath(), null, null);
                    shareIntent = ShareCompat.IntentBuilder.from(this)
                    .setText("Hello from Google+!")
                    .setType("image/jpeg")
                    .setStream(Uri.parse(photoUri))
                    .getIntent()
                    .setPackage("com.google.android.apps.plus");
                    startActivity(shareIntent);
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            break;
        }
    }
    public String takeScreenShot(){
        try{
            RelativeLayout  view = (RelativeLayout)findViewById(R.id.icflag_layout);
            View v1 = view.getRootView();
            System.out.println("Root View : "+v1);
            v1.setDrawingCacheEnabled(true);
            Bitmap bm = v1.getDrawingCache();
            url =MediaStore.Images.Media.insertImage(getContentResolver(), bm,"screeshot.jpg", 1233+ ".jpg Card Image");
        }
        catch(OutOfMemoryError e){

        }
        return url;
    }
}

谢谢和问候

4

2 回答 2

0

Google+ 应用仅支持content:// URIMediaStore为此,您需要使用API。

 File tmpFile = new File("path of the image");
 final String photoUri = MediaStore.Images.Media.insertImage(
         getContentResolver(), tmpFile.getAbsolutePath(), null, null);

 Intent shareIntent = ShareCompat.IntentBuilder.from(this)
         .setText("Hello from Google+!")
         .setType("image/jpeg")
         .setStream(Uri.parse(photoUri))
         .getIntent()
         .setPackage("com.google.android.apps.plus");
于 2013-01-07T07:57:19.143 回答
0

不要使用绝对路径。

OnActivityResult() 在从相机捕获图像后使用它。

Uri photoUri = intent.getData();                
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
                         .setText("Hello From Google+!")
                             .setType("image/jpeg")
                             .setStream(photoUri)
                             .getIntent()
                     .setPackage("com.google.android.apps.plus");
startActivity(shareIntent);

这对我有用。

于 2013-03-05T08:56:30.380 回答