如何将文件上载到sharepoint网站';android上使用Graph API的s文档库

如何将文件上载到sharepoint网站';android上使用Graph API的s文档库,android,microsoft-graph-api,sharepoint-online,Android,Microsoft Graph Api,Sharepoint Online,我正在开发一个android应用程序(Java android),它需要将excel文件上传到sharepoint网站的库中。首先,我使用graph API获取了这个示例: 此示例将图片上载到用户的单驱动器存储库 因此,多亏了graph explorer,我更改了查询,使图片进入我的站点库并正常工作,但当我从android应用程序执行查询时,我出现以下错误: 我的代码: public void uploadPictureToOneDrive(byte[] picture, ICallback&l

我正在开发一个android应用程序(Java android),它需要将excel文件上传到sharepoint网站的库中。首先,我使用graph API获取了这个示例: 此示例将图片上载到用户的单驱动器存储库

因此,多亏了graph explorer,我更改了查询,使图片进入我的站点库并正常工作,但当我从android应用程序执行查询时,我出现以下错误:

我的代码:

public void uploadPictureToOneDrive(byte[] picture, ICallback<DriveItem> callback) {

    try {
        String id = new String("groupeeiffage.sharepoint.com,1f99a971-b596-4c9b-ba31-784d70c05f49,88ea0abd-a92d-412c-b047-86744a64c0ea");
        mGraphServiceClient
                .getSites(id)
                .getDrive()
                .getRoot()
                .getItemWithPath("me.png")
                .getContent()
                .buildRequest()
                .put(picture, callback);
    } catch (Exception ex) {
        showException(ex, "exception on upload picture to OneDrive ","Upload picture failed", "The upload picture  method failed");
    }
}
public void上传图片OneDrive(字节[]图片,ICallback回调){
试一试{
字符串id=新字符串(“groupeeiffage.sharepoint.com,1f99a971-b596-4c9b-ba31-784d70c05f49,88ea0abd-a92d-412c-b047-86744a64c0ea”);
mGraphServiceClient
.getSites(id)
.getDrive()
.getRoot()
.getItemWithPath(“me.png”)
.getContent()
.buildRequest()
.put(图片、回拨);
}捕获(例外情况除外){
showException(例如,“向OneDrive上传图片时出现异常”、“上传图片失败”、“上传图片方法失败”);
}
}
我知道这是一个授权问题,但我在microsoft文档中迷失了方向。如何允许使用Graph API的应用程序将文件上载到sharepoint


如果有人已经做了类似的事情,我真的希望得到一些帮助。

作为一种解决方法,我们可以使用SharePoint REST API在Android中上传文件

  • 从Microsoft身份验证门户获取安全令牌:
  • public String receiveSecurityToken()抛出TransformerException、URISyntaxException{
    RequestEntity RequestEntity=
    新建RequestEntity(buildSecurityTokenRequestEnvelope(),
    HttpMethod.POST,
    新URI(“https://login.microsoftonline.com/extSTS.srf"));
    ResponseEntity ResponseEntity=restTemplate.exchange(requestEntity,String.class);
    DOMResult=新的DOMResult();
    Transformer Transformer=TransformerFactory.newInstance().newTransformer();
    transform(新的StringSource(responseEntity.getBody()),result);
    文档定义文档=(文档)结果.getNode();
    String securityToken=xPathExpression.evaluateAsString(定义文档);
    如果(StringUtils.isBlank(securityToken)){
    抛出新的SharePointAuthenticationException(“无法验证:空令牌”);
    }
    返回securityToken;
    }
    
    发送到门户的信封具有以下格式:

    
    
    

  • 欢迎使用堆栈溢出!既然你是新来的,我建议你阅读一些技巧。您的问题缺少一些关键细节,例如您正在使用的导致错误的代码、您用于获取令牌的代码等。抱歉,我的第一个问题确实缺少很多信息,现在应该会更好谢谢您的回答,我需要在Azure中注册我的应用程序才能做到这一点吗?我开始在你的链接(paulryan.com.au/2014/spo remote authentication rest)之后做一些POST请求,当我发送它时,我收到一个“此联合命名空间不允许直接登录WLID”错误。它是receiveSecurityToken()类,我的用户名和密码放在哪里?你不需要在Azure中注册,我们可以与邮递员或Fiddler一起进行此标记,因此,我们只需要像本文一样,在Java代码中一步一步地调用APIshows@LeeLiu我们必须将这个xml信封传递到哪里?@Anurag_BEHS使用post方法请求是否有dart/FLART包或代码示例,用于将二进制文件从移动设备读写到sharepoint服务器?