read file from sharepoint in android via graph .

Anonymous
2023-03-17T13:24:58+00:00

Its my first time to work with MSAL.

i am using the graph api to read data but i'm getting a sharepoint file link .

i want to download that file into my app but it is giving 403 error code but i can access that file without login with that url on chrome or any other browser .

Q1 is there any special permission required to access share point file on android ?

Q2 can someone share sample auth json file or manifest file ?

Q3 any example to read file in android java or kotlin ?

Microsoft 365 and Office | SharePoint | Other | Android

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-03-18T01:21:53+00:00

    Dear Hemaraj Murthy,

    Good day!!

    Question 1


    Yes, in order to access SharePoint files on Android using the Microsoft Graph API, you will need to obtain the necessary permissions from the SharePoint site administrator. The permissions required to access SharePoint files vary depending on the type of access you need.

    To access SharePoint files via the Microsoft Graph API, you will need to use an authentication flow that grants you the appropriate permissions. This can be done using OAuth 2.0 authentication, which requires you to register your application with Microsoft and obtain an access token.

    Once you have obtained an access token, you can use it to authenticate your requests to the Microsoft Graph API and access SharePoint files. The specific permissions required to access SharePoint files will depend on the type of operation you want to perform (e.g., read, write, or delete files).

    It's also worth noting that you may need to configure your app to work with the Microsoft Graph API and SharePoint specifically, as there are different configuration options and authentication flows depending on the platform and scenario you are working with.

    Question 2


    I assume you are asking for a sample authentication JSON file or manifest file. However, I'm not sure what specific context you are referring to as authentication and manifest files can vary depending on the platform or application.

    Here's an example of an authentication JSON file for a simple web application using JWT (JSON Web Token) authentication:

    {

    "secret": "mysecretpassword",

    "expiresIn": "1h"

    }

    In this example, the file contains the secret key used to sign and verify the JWT tokens, as well as the expiration time for the tokens.

    As for a manifest file, again, it depends on what platform or application you are referring to. Here's an example of a basic manifest file for a Node.js application

    {

    "name": "my-app",

    "version": "1.0.0",

    "description": "My Node.js app",

    "main": "index.js",

    "dependencies": {

    "express": "^4.17.1"
    

    },

    "scripts": {

    "start": "node index.js"
    

    },

    "author": "John Doe",

    "license": "MIT"

    }

    This manifest file provides information about the application, such as its name, version, description, entry point, dependencies, scripts, author, and license. This information can be used by tools like package managers to install and manage the application and its dependencies.

    Question 3:


    Here's an example of how to read a file in Android using both Java and Kotlin:

    Java:

    try {

    InputStream inputStream = context.openFileInput("filename.txt");
    
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    
    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
    
    StringBuilder stringBuilder = new StringBuilder();
    
    String line;
    
    while ((line = bufferedReader.readLine()) != null) {
    
        stringBuilder.append(line).append("\n");
    
    }
    
    inputStream.close();
    
    String fileContents = stringBuilder.toString();
    

    } catch (IOException e) {

    e.printStackTrace();
    

    }

    Kotlin:

    try {

    val inputStream: InputStream = context.openFileInput("filename.txt")
    
    val inputStreamReader = InputStreamReader(inputStream)
    
    val bufferedReader = BufferedReader(inputStreamReader)
    
    val stringBuilder = StringBuilder()
    
    var line: String?
    
    while (bufferedReader.readLine().also { line = it } != null) {
    
        StringBuilder.append(line).append("\n")
    
    }
    
    inputStream.close()
    
    val fileContents = StringBuilder.toString()
    

    } catch (e: IOException) {

    e.printStackTrace()
    

    }

    If the above information doesn't help, I suggest you to post your concern in the Microsoft Q&A Community to get detailed help from experts.

    Thanks for your patience and understanding!!

    Best Regards,

    Was this answer helpful?

    0 comments No comments